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.
Interface
No new interfaces are introduced.
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
Let me update my reproduction script to mirror this config more closely for sqlite:
Assistant
Now let's write a reproduction test using the Migrator with an entity that has a
@Trigger, to confirm this exact bug.Assistant
Now let's add the missing
setTriggerscall:Assistant
The fix resolves the trigger case. Now let's run the full existing migrations test suite plus trigger tests, and the broader schema-generator tests to ensure nothing broke.
Assistant
Confirmed these 3 failures (postgres/mssql connection refused) are pre-existing, unrelated to our fix — this environment simply lacks running DB servers for those dialects.
Now let's run the broader schema-generator suite (sqlite/mongo) to make sure nothing else broke, and also check mongo migrations module for a similar
getSchemaFromSnapshot(unlikely since mongo doesn't have triggers, but let's check).Assistant
Good, no mongo equivalent (mongo doesn't have triggers). Now let's run the full sqlite-related schema-generator and migrations test suites, plus the trigger tests, to be safe.
Assistant
All sqlite tests pass, and Migrator.mongo also passes. Now let's view the final diff and clean up temp files.
Assistant
Clean. Now let's also double check for edge cases — e.g., older snapshots without a
triggersfield (backward compatibility) and empty triggers array.Assistant
Good, consistent internal API. The fix is minimal, correct, and matches the existing pattern exactly. Let's do a final full check of the diff and run the complete sqlite migration test suite once more to be certain.
Assistant
All pass. Let's clean up temp artifacts and finalize.
Assistant
Checklist review
- I have successfully reproduced the error: Yes. I built a temporary reproduction test (, later removed) using a ORM instance with an entity decorated with . After + , the snapshot file on disk correctly contained the array for the table, but never called when re-hydrating a from the JSON snapshot (unlike //, which were all wired up). This meant every subsequent read of the snapshot silently dropped the trigger info, so any diff computed against that "from schema" (e.g. right after ) incorrectly proposed recreating triggers that already existed in the database — i.e. "the snapshot changes and a bunch of stuff in the snapshot is wrong," matching the reported symptom on .
Assistant
The change is minimal, targeted, and verified. Submitting now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.