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
Both SQLite and libSQL use
SqlitePlatform, so one override covers both. The repro README references issue #7798. Let me look at the analogous MySQL regression test (GH7796) as a template, then write the failing test first. - Assistant
Now write the failing regression test:
- Assistant
Both fail as expected. Now the fix. First the platform capability flag:
- Assistant
Now
DatabaseTable.toJSON(): - Assistant
Now the comparator — skip comment diffs when the platform can't persist them:
- Assistant
Both pass. Check for name collisions and run the broader affected test suites:
- Assistant
Many failures — likely missing database containers rather than my change. Let me check:
- Assistant
While that runs, let me check whether there are serialized-snapshot fixtures in tests that assert the old behavior (comment emitted on sqlite):
- Assistant
While that runs, validate types and build:
- Assistant
Two watchers are armed on the test run; I'll wait for their notifications before concluding.
- Assistant
All checks except the long-running migrations+issues suite are done; nothing further to do until it finishes.
- Assistant
Tests are running (vitest workers active; output buffered through the
tailpipe until completion). Waiting for the completion notification. - Assistant
All done. Summary of the fix:
Root cause
Since #7210's fix,
migrator.up()/down()rewrite.snapshot-<db>.jsonfrom DB introspection, whilemigration:createwrites it from entity metadata. #7608 and #7797 stabilized the two serializations for postgres/mysql, but SQLite has a divergence that can't be recovered: SQLite does not persist comments at all, so introspection always yieldscomment: nullwhile metadata yields the configured string — exactly the flip the reproduction shows ("free-form notes"→nullafternpm run migrate).The same root cause was also silently worse than the snapshot churn: a column comment on SQLite made the comparator flag a
changedColumnsdiff on everyschema:update, andSqliteSchemaHelper.alterTable()responds to any changed column with a full temp-table rebuild.Changes
packages/core/src/platforms/Platform.ts— new capabilitysupportsComments()(defaulttrue): whether comments are persisted in the DB and introspectable.packages/sql/src/dialects/sqlite/SqlitePlatform.ts— override returningfalse(covers both@mikro-orm/sqliteand@mikro-orm/libsql, which share the platform).packages/sql/src/schema/DatabaseTable.ts:1367,1469—toJSON()emitscomment: nullfor columns and the table when the platform can't persist comments, so metadata-side and introspection-side snapshots agree.packages/sql/src/schema/SchemaComparator.ts:954—diffComment()returnsfalseon such platforms, so the (now comment-less) snapshot vs. the in-memory target no longer flags a diff and triggers a bogus table rebuild.
For comment-supporting platforms this is a strict no-op:
supportsComments()staystrue, making both expressions identical to what was there before.Test
tests/issues/GH7798.test.ts(written first, failed on both counts before the fix) mirrors the reproduction: entity with table + column comments,createInitial()→up()→ snapshot must be byte-identical, secondcreate()must be an empty diff, andgetUpdateSchemaSQL()must be empty.Verification
tests/issues/GH7798.test.ts— 2 passed (both failed before the fix)yarn test sqlite— 57 files / 674 tests passed (includes the #7608 snapshot round-trip tests)yarn test libsql— passedyarn lint(incl. tsgo type-check),yarn build,yarn format— all clean
One caveat to report honestly: the full
yarn testsuite can't run in this environment — there's no Docker, so all postgres/mysql/mariadb/mssql-backed tests fail withECONNREFUSEDregardless of this change (I confirmed the failures are connection errors, and killed one such run after it stalled 43 minutes on retries). Those platforms are unaffected by this change by construction, but CI should confirm.
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 →
- 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 →