orm.migrator.up() rewrites snapshot incorrectly Describe the bug When we run…
- User
orm.migrator.up()rewrites snapshot incorrectlyDescribe the bug
When we run
orm.migrator.up(), the snapshot changes and a bunch of stuff in the snapshot is wrong and we have to revert the changes.Reproduction
https://github.com/zachkirsch/mikro-orm-migrate-snapshot-repro
What driver are you using?
@mikro-orm/sqlite
MikroORM version
7.1.2-dev.10
Node.js version
v24.0.1
Operating system
macOS
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord.
- The provided reproduction is a minimal reproducible example of the bug.
Interface
No new interfaces are introduced.
- Assistant
I'll investigate the snapshot rewrite bug by exploring the reproduction repo and the migrator snapshot logic in MikroORM.
- Assistant
Implementing metadata enrichment so introspected snapshots keep comments SQLite can't store in the database.
- Assistant
The bug was in
runMigrations: aftermigrator.up(), the snapshot was rewritten from database introspection. SQLite doesn't persist column comments, so metadata-only values like"free-form notes"were lost and the snapshot file changed on every migrate.Root cause
migration:createwrites the snapshot from entity metadata (getTargetSchema()), butmigration:upwas overwriting it withDatabaseSchema.create()(introspection). On SQLite, column comments exist only in metadata, not in the DB.Fix
- Added
DatabaseSchema.enrichFromMetadata()to copy metadata-only details (table/column comments) from the target schema into the introspected schema. - Called it in
Migrator.runMigrations()after introspection, before writing the snapshot.
This keeps introspection accurate for structural changes (including custom migration SQL) while preserving metadata-only fields that the DB can't round-trip.
Verification
- Added
tests/features/migrations/GH7798.test.ts - All existing
Migrator.sqlite.test.tstests pass - Confirmed against the : is clean after
- Added
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.