payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
27.81k stars 1.73k forks source link

feat(db-sqlite): add `autoIncrement` option #9427

Open r1tsuu opened 15 hours ago

r1tsuu commented 15 hours ago

What?

Exposes ability to enable AUTOINCREMENT for Primary Keys which ensures that the same ID cannot be reused from previously deleted rows.

sqliteAdapter({
  autoIncrement: true
})

Why?

This may be essential for some systems. Enabled autoIncrement: true also for the SQLite Adapter in our tests, which can be useful when testing whether the doc was deleted or not when you also have other create operations.

How?

Uses Drizzle's autoIncrement option.

WARNING: This cannot be enabled in an existing project without a custom migration, as it completely changes how primary keys are stored in the database.

akhrarovsaid commented 15 hours ago

You are a gentleman and a scholar.

For context: I brought this up exactly once in Discord and now we have a feature for it. Incredible.

denolfe commented 9 hours ago

WARNING: This cannot be enabled in an existing project without a custom migration, as it completely changes how primary keys are stored in the database.

It feels like this migration should be provided. It's very likely someone will start a project and stumble upon this option afterward.

r1tsuu commented 7 hours ago

WARNING: This cannot be enabled in an existing project without a custom migration, as it completely changes how primary keys are stored in the database.

It feels like this migration should be provided. It's very likely someone will start a project and stumble upon this option afterward.

The only way to do this is:

But I'm not sure how it will be handled with drizzle snapshots (and will be?) 🤔 .