Skip to content
TheChatArchiveThe Chat Archive
fable-5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

orm.migrator.up() rewrites snapshot incorrectly Describe the bug When we run…

  1. User

    orm.migrator.up() rewrites snapshot incorrectly

    Describe 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

    Interface

    No new interfaces are introduced.

  2. 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.

  3. Assistant

    Now write the failing regression test:

  4. Assistant

    Both fail as expected. Now the fix. First the platform capability flag:

  5. Assistant

    Now DatabaseTable.toJSON():

  6. Assistant

    Now the comparator — skip comment diffs when the platform can't persist them:

  7. Assistant

    Both pass. Check for name collisions and run the broader affected test suites:

  8. Assistant

    Many failures — likely missing database containers rather than my change. Let me check:

  9. Assistant

    While that runs, let me check whether there are serialized-snapshot fixtures in tests that assert the old behavior (comment emitted on sqlite):

  10. Assistant

    While that runs, validate types and build:

  11. Assistant

    Two watchers are armed on the test run; I'll wait for their notifications before concluding.

  12. Assistant

    All checks except the long-running migrations+issues suite are done; nothing further to do until it finishes.

  13. Assistant

    Tests are running (vitest workers active; output buffered through the tail pipe until completion). Waiting for the completion notification.

  14. Assistant

    All done. Summary of the fix:

    Root cause

    Since #7210's fix, migrator.up()/down() rewrite .snapshot-<db>.json from DB introspection, while migration:create writes 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 yields comment: null while metadata yields the configured string — exactly the flip the reproduction shows ("free-form notes" → null after npm run migrate).

    The same root cause was also silently worse than the snapshot churn: a column comment on SQLite made the comparator flag a changedColumns diff on every schema:update, and SqliteSchemaHelper.alterTable() responds to any changed column with a full temp-table rebuild.

    Changes

    • packages/core/src/platforms/Platform.ts — new capability supportsComments() (default true): whether comments are persisted in the DB and introspectable.
    • packages/sql/src/dialects/sqlite/SqlitePlatform.ts — override returning false (covers both @mikro-orm/sqlite and @mikro-orm/libsql, which share the platform).
    • packages/sql/src/schema/DatabaseTable.ts:1367,1469 — toJSON() emits comment: null for 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() returns false on 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() stays true, 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, second create() must be an empty diff, and getUpdateSchemaSQL() 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 — passed
    • yarn lint (incl. tsgo type-check), yarn build, yarn format — all clean

    One caveat to report honestly: the full yarn test suite can't run in this environment — there's no Docker, so all postgres/mysql/mariadb/mssql-backed tests fail with ECONNREFUSED regardless 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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.