ISSUE DESCRIPTION orm.migrator.up() rewrites snapshot incorrectly Describe the bug When…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. - Assistant
I’ll inspect the repository structure and migration/snapshot code, identify how
migrator.up()persists snapshots, reproduce with the relevant existing tests or a focused script, then implement and verify a targeted fix without modifying tests. - Assistant
rgis unavailable in the environment, so I’ll usegrep/findinstead. I’m narrowing the search to schema-generator, migrator, and snapshot-related tests. - Assistant
The regression is in
Migrator.runMigrations: it introspects the live database and rewrites the snapshot after every successful migration, includingup. A snapshot created withmigration:createrepresents the target metadata schema; rewriting it from dialect introspection introduces serialization/driver differences and causes the reported noisy changes. I’ll restore the intended lifecycle: onlydownrefreshes the snapshot, because rollback makes the database diverge from the target snapshot. I’ll retain transaction-context support and the read-only protection for thedownpath. - Assistant
The environment also lacks
python3; I’ll apply the same small source change with a portable Perl replacement, then inspect the diff. - Assistant
The diff now limits snapshot introspection/writes to
down. I’ll run the migrations SQLite test file to catch compilation or unrelated regressions; I expect the repository’s older test that explicitly requires anupwrite may fail because it encodes the behavior this issue asks to remove. I’ll also run the migrations package build/type check if available. - Assistant
The test/build commands exceeded the terminal’s short execution limit before producing results, rather than reporting code failures. The source change is type-neutral (
methodis already the declared'up' | 'down'union). I’ll perform a fast compile invocation if possible, inspect repository status, and verify no generated artifacts or accidental changes remain. - Assistant
Compilation is also exceeding the command time limit in this monorepo, with no diagnostic output. The only working-tree change is the guarded condition in
Migrator.ts, andgit diff --checkhas produced no whitespace errors. This directly preventsupfrom invokingDatabaseSchema.create()or writing the snapshot, while preservingdownbehavior.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.