Migrations

Edited migrations

Why an applied migration never runs again, how applyMigrations notices an edited file, and the way out.

Applied migrations never run again. A file edited or removed after it was applied, for example drizzle-kit generate rewriting the last migration while the schema is still in flux, leaves the local database built from files production will never see.

applyMigrations records the sha256 digest of each migration it applies, in nuxt_pglite.migration_digest, and before applying anything checks the applied ones against their files. Any edited or removed throws a MigrationDriftError listing them in details:

Applied migrations no longer match their files:
  - 20261008032022_init: edited
Applied migrations never run again: reset the local database to apply the current files.

Thrown from init, it leaves the development socket refusing clients with that message, so the mistake shows up in nuxt dev rather than in production.

The way out

Start the local database over and let init apply the current files from scratch: run the reset-database action from the DevTools tab. Migrations applied before digests were recorded get theirs recorded as their files are now.

Once a migration has reached a shared or production database, do not edit it: add a new one that changes what it did.

Options

digests decides where the digests are kept:

export default definePGliteServerConfig({
  init: (pg) => applyMigrations(pg, migrations, { digests: 'public.migration_digests' }),
})

The digests table cannot be the tracking table.