Skip to content
TheChatArchiveThe Chat Archive
composer-2.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

    I'll investigate the snapshot rewrite bug by exploring the reproduction repo and tracing how migrator.up() handles snapshots in MikroORM.

  3. Assistant

    I'll reproduce the bug locally, then implement a fix to preserve metadata-only fields when introspection rewrites the snapshot.

  4. Assistant

    Implementing enrichFromMetadata to copy metadata-only fields introspection can't recover, then adding a test.

  5. Assistant

    The bug was that migrator.up() rewrites the snapshot from database introspection, while migration:create writes it from entity metadata. On SQLite, column comments exist only in metadata — SQLite does not persist them — so after up() the snapshot lost comments like "free-form notes" and flipped to null.

    Fix

    1. DatabaseSchema.enrichFromMetadata() — After introspection, copies metadata-only fields from the entity-derived schema when the database cannot provide them (column/table comment, ignoreSchemaChanges, nativeEnumName, extra).

    2. Migrator.runMigrations() — Calls enrichFromMetadata(getTargetSchema()) before writing the snapshot after up()/down().

        if (result.length > 0 && this.options.snapshot) {
          const ctx = Utils.isObject<MigrateOptions>(options) ? options.transaction : undefined;
          const schema = await DatabaseSchema.create(
            this.em.getConnection(),
            this.em.getPlatform(),
            this.config,
            undefined,
            undefined,
            undefined,
            undefined,
            undefined,
            ctx,
          );
          schema.enrichFromMetadata(this.#schemaGenerator.getTargetSchema());
    
          try {
            await this.storeCurrentSchema(schema);
    

    Test

    Added tests/issues/GH7798.test.ts matching the reproduction repo: an entity with @Property({ comment: 'free-form notes' }) on SQLite. The test confirms the snapshot is unchanged after migrator.up() and a second migration:create produces an empty diff.

    All 24 sqlite migrator tests pass. The fix keeps introspection as the base (reflecting actual DB structure) while preserving metadata-only details that platforms like SQLite cannot introspect.

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