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 migrator snapshot rewrite bug by exploring the codebase and the reproduction repo.
- Assistant
Reproducing the bug locally, then applying the fix.
- Assistant
Bug confirmed:
runMigrationsintrospects the DB onup(), which drops SQLite column comments. Switchingup()to use metadata-basedgetTargetSchema()likecreate()does. - Assistant
Now I'll add a test that verifies column comments survive
migrator.up(). - Assistant
Root Cause
After
migrator.up(), the snapshot was rebuilt from database introspection (DatabaseSchema.create()). On SQLite, column comments are metadata-only — they aren't stored in the DB and aren't returned by introspection — so values like"free-form notes"were rewritten tonull.When creating migrations, the snapshot is written from entity metadata (
getTargetSchema()), which does include comments. That mismatch causedmigrator.up()to corrupt the committed snapshot.Fix
In
runMigrations,upnow uses the same metadata-based path as :
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.