Skip to content

[P0][bug] compareSchemas normalizes DDL via whitespace+lowercase — string-literal changes are reported identical #371

Closed

Description

@EVWorth

Context

Schema Compare & Sync treats views/routines/triggers DDL as opaque strings.

Problem

src/lib/schema-diff.ts:163-186 uses normalizeDdl = ddl => ddl.replace(/\s+/g, ' ').trim().toLowerCase(). The lowercase collapses string literals, so two views that differ only in a string literal inside the SELECT are reported identical. Concrete: CREATE VIEW v AS SELECT * FROM users WHERE name = 'Alice' and ... name = 'alice' lowercased to the same 'alice' — reported identical even though the row sets differ. Same trap for default values, comments, function bodies. Table columns are compared field-by-field and don't have the bug; views/routines/triggers do. The sync generator would emit CREATE OR REPLACE VIEW v AS <source-ddl> on a re-compare, but the diff UI shows the views as identical — no user signal that a sync is needed.

Files

  • src/lib/schema-diff.ts:11 (normalizeDdl)
  • src/lib/schema-diff.ts:163-186 (callers)

Repro

  1. Create two views: v1 SELECT * FROM users WHERE name = 'Alice' and v2 SELECT * FROM users WHERE name = 'bob'
  2. Schema Compare source/target
  3. Both views report as "identical" — wait, the second example SHOULD differ ("Alice" vs "bob"). Use Alice vs alice to confirm the bug.

Expected

Two views that differ inside a string literal are reported as "different".

Proposed fix

Replace normalizeDdl with a tokenizer that normalises structural tokens (keywords, identifiers, operators, whitespace) while preserving string-literal contents verbatim. Or compute a server-side checksum: MD5(SHOW CREATE VIEW v) for views, MD5(SHOW CREATE PROCEDURE p) for routines (MySQL allows SHOW CREATE on these). Pass hashes from snapshot fetch and compare by hash. Add unit tests covering the false-positive cases. Scope: M.

Acceptance

Two views that differ only inside a string literal in the SELECT list are reported as "different". Two views that differ only in formatting (whitespace, keyword case) are reported as identical.

Needs human verify

yes

Activity

  1. added
    audit
    severity/p0
    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/p0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions