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
I'll start by exploring the repository structure and understanding the issue with
orm.migrator.up()rewriting snapshots incorrectly. - Assistant
Let me look at the migrator code and search for snapshot-related logic.
- Assistant
Let me look at the migrations package and see recent changes related to snapshots.
- Assistant
Let me examine the Migrator and migration snapshot handling carefully.
- Assistant
Let me inspect the snapshot write/store logic and related recent changes.
- Assistant
Let me examine how
up()handles snapshots and any related store logic. - Assistant
The snapshot rewrite during
up()seems concentrated aroundrunMigrations— I'll inspect that next. - Assistant
I'll search the changelog and related issues for snapshot-rewriting bugs during migrations.
- Assistant
I'll inspect how DatabaseSchema is serialized and what recently changed for snapshot stability.
- Assistant
I'll try to fetch the reproduction repository to see what's going wrong.
- Assistant
Good, the clone worked. Let me explore the reproduction.
- Assistant
The issue appears linked to SQLite column comments — I'll inspect the reproduction files next.
- Assistant
I'll dig into how SQLite handles comments in schema generation and comparison.
- Assistant
I'll check whether SQLite or the platform marks comments as unsupported.
- Assistant
Let me look at how SQLite schema helper handles comments, and schema generator skip comments for SQLite.
- Assistant
Looking at SchemaHelper line 547 - if the only change is comment, something special happens. Let me read that.
- Assistant
Let me look at SqliteSchemaHelper regarding comments and inspect the DatabaseSchema.create introspection path.
- Assistant
Checking whether SQLite ignores comments during schema comparison.
- Assistant
I'll check how SQLite writes column comments and which fields the serializer keeps.
- Assistant
I'll examine createTableColumn and column XML comment handling next.
- Assistant
I'll review the stabilize commit and SQLite-related snapshot tests next.
- Assistant
There's a Migrator.sqlite.test.ts. Let me look it and the toJSON method for DatabaseTable.
- Assistant
There's already a test for snapshot serialization stability. The existing entities in tests may not have comments. The repro uses column comments.
- Assistant
I'll check SQLite support around column-comment changes next.
- Assistant
I'll check comment support flags on the platform next.
- Assistant
I'll check SQLite's getColumns system and see if table comments round-trip.
- Assistant
Wrong file - need SqliteSchemaHelper getColumns
- Assistant
I'll check alterTableComment usage and schema generator handling for SQLite comments.
- Assistant
I'll check whether empty comment SQL ends up in migration diffs.
- Assistant
I'll trace how empty SQL lines are filtered in the schema generator.
- Assistant
Let me check SchemaHelper.append - does it filter empties?
- Assistant
Let me look at append method at line 910
- Assistant
I'll check how MSSQL and Oracle handle comments.
- Assistant
I'll look for the appendComments implementation.
- Assistant
I'll inspect the parseTableDefinition and DDL comment strategy.
- Assistant
I'll check LibSQL platform inheritance and then try reproducing the issue.
- Assistant
I'll check the build state and try to reproduce with the local packages.
- Assistant
Packages expose TypeScript sources directly, so I'll reproduce skr independently.
- Assistant
better-sqlite3 may not be built — I'll try running the repro and linking local packages if needed.
- Assistant
It ran. Let me check the git diff.
- Assistant
Confirmed. Now I'll implement the_fix and check where platform capabilities are defined.
- Assistant
Need to cd back to the repo.
- Assistant
Looking at this more carefully, I wonder if a cleaner approach exists.
- Assistant
I'll check AbstractSqlPlatform and implement the fix.
- Assistant
I'll implement comments overlay from the target schema when the platform can't introspect them.
- Assistant
I'll add supportsColumnComments and supportsTableComments to Platform with default true (so existingdrivers worklined), SQLite overrides to false.
- Assistant
getTable only takes_name, not_schema. Let me see how_schema-qualified tables work.
- Assistant
I'll check SchemaComparator and how getTargetSchema works next.
- Assistant
Implementing platform flags and overlaying non-introspectable comments when rewriting snapshots.
- Assistant
The edit landed in the wrong file — I'll fix SchemaComparator first.
- Assistant
Good, SchemaComparator is restored. Now edit Platform.ts correctly.
- Assistant
Good. Now, add these to AbstractSqlPlatform as true and set SQLite to false.
- Assistant
I'll fix the typo and update Migrator plus SchemaComparator.
- Assistant
I'll also skip comment diffs when unsupported and make SQLite's alterTableComment a no-op.
- Assistant
I'll update diffComment usages and the method itself_to check_platform.
- Assistant
I'll restore the SQLite table-comment trailer to avoid breakingschema SQL dumps.
- Assistant
I'll override SQLite's alterTableComment and check the LibSQL platform.
- Assistant
Add alterTableComment override.
- Assistant
Now I'll verify the fix against the reproduction.
- Assistant
I need better-sqlite3 and possibly tsx and core deps.
- Assistant
It ran successfully — I'll check the git diff.
- Assistant
Clean diff — the fix works. Next I'll run the existing migrator SQLite tests.
- Assistant
The test timed out — I'll try a more direct vitest run.
- Assistant
All migrator SQLite tests passed. I'll before a temporary script for the comment case, then remove it.
- Assistant
Need reflect-metadata import first.
- Assistant
I'll put the script inside the repo so package resolution works.
- Assistant
Both comment types stay preserved. I'll clean up and review the final diff.
- Assistant
I'll restore the blank line for a cleaner diff.
- Assistant
I need to restore the createTable method — the last edit corrupted it.
- Assistant
Good, file restored. Now carefully add only the alterTableComment.
- Assistant
I'll re-run the verification and check the final status.
- Assistant
All checks pass. Submitting the fix.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.