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 tracing how
migrator.up()handles snapshots in MikroORM. - Assistant
I'll reproduce the bug locally, then implement a fix to preserve metadata-only fields when introspection rewrites the snapshot.
- Assistant
Implementing
enrichFromMetadatato copy metadata-only fields introspection can't recover, then adding a test. - Assistant
The bug was that
migrator.up()rewrites the snapshot from database introspection, whilemigration:createwrites it from entity metadata. On SQLite, column comments exist only in metadata — SQLite does not persist them — so afterup()the snapshot lost comments like"free-form notes"and flipped tonull.Fix
-
DatabaseSchema.enrichFromMetadata()— After introspection, copies metadata-only fields from the entity-derived schema when the database cannot provide them (column/tablecomment,ignoreSchemaChanges,nativeEnumName,extra). -
Migrator.runMigrations()— CallsenrichFromMetadata(getTargetSchema())before writing the snapshot afterup()/down().
if (result.length > 0 && this.options.snapshot) { const ctx = Utils.isObject<MigrateOptions>(options) ? options.transaction : undefined; const schema = await DatabaseSchema.create( this.em.getConnection(), this.em.getPlatform(), this.config, undefined, undefined, undefined, undefined, undefined, ctx, ); schema.enrichFromMetadata(this.#schemaGenerator.getTargetSchema()); try { await this.storeCurrentSchema(schema);Test
Added
tests/issues/GH7798.test.tsmatching the reproduction repo: an entity with@Property({ comment: 'free-form notes' })on SQLite. The test confirms the snapshot is unchanged aftermigrator.up()and a secondmigration:createproduces an empty diff.All 24 sqlite migrator tests pass. The fix keeps introspection as the base (reflecting actual DB structure) while preserving metadata-only details that platforms like SQLite cannot introspect.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →