Skip to content

Fix MSSQL import of exported scripts - #1118

Open
yzxcj797 wants to merge 1 commit into
drawdb-io:mainfrom
yzxcj797:fix-mssql-import-roundtrip
Open

Fix MSSQL import of exported scripts#1118
yzxcj797 wants to merge 1 commit into
drawdb-io:mainfrom
yzxcj797:fix-mssql-import-roundtrip

Conversation

@yzxcj797

Copy link
Copy Markdown

Summary

Scripts exported from the MSSQL generator could not be imported again. Two parser-boundary cases caused the failure:

  • a semicolon-terminated statement followed by a GO batch separator;
  • ALTER TABLE ... ADD FOREIGN KEY, which the current transactsql grammar in node-sql-parser does not support.

MSSQL import now normalizes GO batches into statement separators before parsing. Foreign-key ALTER statements are extracted, converted to the equivalent MySQL ALTER syntax accepted by the parser, and converted back into the AST shape fromMSSQL already consumes. Named constraints, schema-qualified tables, quoted identifiers, composite column lists, referential actions, scripts without semicolons, and single-statement inputs are covered.

Fixes #320.

Testing

  • npm test — 8/8 tests pass
  • npm run lint — passes with zero warnings
  • npm run build — passes (existing lottie-web eval and large-chunk warnings remain)
  • git diff --check — passes
  • The development server starts successfully with the modified import path.

The new tests cover exported-style table/FK round trips, GO with and without semicolons, named constraints, ON UPDATE/ON DELETE actions, extended-property EXEC batches, no-GO input, single non-terminated statements, and multi-line foreign-key column lists.

The transactsql grammar of node-sql-parser cannot parse ALTER TABLE ... ADD FOREIGN KEY statements and fails on semicolon-terminated statements followed by GO batch separators, which broke importing scripts exported by the MSSQL exporter.

Parse GO batches as semicolon-separated statements and parse extracted foreign key definitions with the mysql grammar, which produces the alter statement shape fromMSSQL already handles. Add vitest and round-trip regression tests.
@vercel

vercel Bot commented Aug 18, 2026

Copy link
Copy Markdown

@yzxcj797 is attempting to deploy a commit to the dottle's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Cannot import MSSQL file previously exported

1 participant