Skip to content

[P1][bug] compareColumns ignores column order — reorder is reported identical #374

Closed

Description

@EVWorth

Context

Schema Compare column-level diff is supposed to surface all structural changes.

Problem

src/lib/schema-diff.ts:60-100 (compareColumns) builds sourceMap = new Map(sourceColumns.map((c) => [c.name, c])) and iterates the map. A column reorder (source id, name, email vs target id, email, name) compares each column by name and finds all three — all equal, no diff. The diff reports the table as identical. sync-sql-generator won't emit any ALTER, but ALTER TABLE … MODIFY COLUMN x AFTER y would be needed to restore source order. This is a silent schema drift: a query that relies on column order (e.g., INSERT INTO t VALUES (…) without column names) would write different rows on each side.

Files

  • src/lib/schema-diff.ts:60-100

Repro

  1. Create source.users (id INT, name VARCHAR(50), email VARCHAR(255))
  2. Create target.users (id INT, email VARCHAR(255), name VARCHAR(50))
  3. Schema Compare — table appears as identical

Expected

Diff surfaces a "Column order changed" entry; sync SQL emits MODIFY COLUMN statements to reorder.

Proposed fix

Track ordinal position per column. Add orderChanged: boolean to the table diff when [src_names].join(',') !== [tgt_names].join(',') while set contents match. sync-sql-generator adds ALTER TABLE … MODIFY COLUMN x AFTER y (or FIRST) when orderChanged. Scope: M.

Acceptance

Source id, name, email vs target id, email, name surfaces as a "Column order changed" diff entry; sync SQL emits MODIFY COLUMN statements to reorder.

Needs human verify

yes

Doc drift

no

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/compare
    on Jul 31, 2026
  2. EVWorth commented on Sep 9, 2026

    @EVWorth
    OwnerAuthor

    Closed by removing the feature.

    Schema compare could not back the claim it made — foreign keys were absent from the snapshot entirely, DDL was compared after lowercasing and collapsing whitespace, and column order was ignored — while the sync half could leave a target half-migrated. A compare tool that is quietly wrong is worse than none, because people act on its answer.

    Fixing that properly is a real piece of work, most of it a genuine DDL comparison rather than string normalisation, and the feature is not part of how this project is used. Removed rather than carried: the history has it if someone wants it back.

    Removed in the PR closing this issue: SchemaCompare, SyncPreview, schema-diff, sync-sql-generator, their tests, the compare editor tab type, and the menu, title-bar and toolbar entry points.

  3. added a commit that references this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/compareauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions