Skip to content

[P0][bug] SchemaSnapshot has no foreignKeys field — schema diff silently misses all FK changes; sync generator emits no FK DDL #370

Closed

Description

@EVWorth

Context

Schema Compare & Sync generates CREATE/ALTER/DROP statements to bring target in line with source. FK changes are the most impactful schema changes (they affect row-level integrity).

Problem

SchemaSnapshot.tables[i] carries only { name, columns, indexes } (src/lib/schema-diff.ts:46-57). No foreignKeys field. There is no getForeignKeys Tauri command in src-tauri/src/lib.rs:180-230 invoke_handler (ARCHITECTURE §5.3 lists it but unimplemented). compareSchemas cannot diff FKs; generateSyncSQL cannot emit ADD CONSTRAINT … FOREIGN KEY … or DROP FOREIGN KEY …. A diff between source orders (FK to users) and target orders (no FK) shows as identical — silently dropping the most impactful schema change. Same root cause affects Table Designer (designer F9) — fixing this unblocks both.

Files

  • src/lib/schema-diff.ts:46-57 (SchemaSnapshot interface)
  • src/components/compare/SchemaCompare.tsx:75-130 (fetchSnapshot)
  • src/lib/sync-sql-generator.ts (no FK section)
  • src-tauri/src/lib.rs:180-230 (invoke_handler)
  • src-tauri/crates/mas-core/src/schema/inspector.rs (no FK method)

Repro

  1. Create source DB with orders table referencing users(id)
  2. Create target DB with orders table but no FK
  3. Schema Compare shows: "0 only in source, 0 only in target, 0 different, N identical"
  4. Generate Sync SQL produces: empty list

Expected

Diff surfaces the FK as "Foreign Key Changes" with source/target details; sync SQL emits ALTER TABLE orders ADD CONSTRAINT … FOREIGN KEY ….

Proposed fix

(1) Add pub async fn get_foreign_keys(connection_id, database, table) -> Result<Vec<ForeignKeyInfo>, CoreError> in mas-core/src/schema/inspector.rs querying INFORMATION_SCHEMA.KEY_COLUMN_USAGE joined with REFERENTIAL_CONSTRAINTS and REFERENCED_TABLE_NAME. (2) Register in lib.rs:invoke_handler. (3) Add TS type ForeignKeyInfo and api.getForeignKeys. (4) Extend SchemaSnapshot.tables[i].foreignKeys. (5) Add compareForeignKeys to schema-diff.ts (added/removed/modified). (6) Extend sync-sql-generator.ts with ADD CONSTRAINT and DROP FOREIGN KEY. (7) Add "Foreign Key Changes" section to DiffTableItem UI. Scope: L.

Acceptance

Source orders.user_id → users.id FK with target no FK surfaces as yellow diff item; sync SQL emits ALTER TABLE orders ADD CONSTRAINT … FOREIGN KEY …. Source no FK + target FK surfaces as diff and sync emits ALTER TABLE orders DROP FOREIGN KEY ….

Needs human verify

yes

Doc drift

yes — ARCHITECTURE §5.3 get_foreign_keys command unimplemented

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