refactor(prisma): delegate validator checks to dsql-lint#411
Closed
refactor(prisma): delegate validator checks to dsql-lint#411
Conversation
Replace the custom Prisma-specific SQL transformation code (transform.ts) with dsql-lint, the shared DSQL compatibility linter from aurora-dsql-tools. This removes ~450 lines of hand-rolled SQL parsing and transformation in favor of dsql-lint --fix, which covers significantly more rules (SERIAL, JSON/JSONB, arrays, TEMPORARY tables, triggers, PARTITION BY, sequences, CACHE, multi-DDL transactions, and more). Changes: - Add dsql-lint.ts: binary resolution utility (DSQL_LINT_PATH env, PATH) - Rewrite transform.ts: thin wrapper around dsql-lint --fix - Update index.ts: add 'lint' subcommand, remove --force/--no-header - Clean stderr output: strip temp file paths from dsql-lint diagnostics - Update tests: 47 tests covering transform, lint, CLI, and workflows - Update README: document dsql-lint prerequisite, lint command, new transformer capabilities The Prisma schema validator (validate.ts) is unchanged since dsql-lint operates on SQL, not .prisma files.
The transform/workflow/cli-integration tests now shell out to dsql-lint. Install it via cargo install with caching to avoid rebuilding each run.
The which subprocess didn't reliably respect process.env.PATH changes, causing the "dsql-lint not found" test to fail in CI where the binary was installed. Searching PATH directories in-process is both faster and correctly honors runtime PATH modifications.
- Restore dropped test assertions in transform.test.ts and workflow.test.ts - Add tests for DROP statements, compound ALTER TABLE, reserved word table names, FK with ON DELETE CASCADE, partially transformed indexes - Replace transformer rules table in README with link to dsql-lint docs - Simplify migrate step 3 description
- Add back examples in migrate help text (pkale comment #1) - Restructure stderr/exitCode logic: always print stderr for diagnostics, gate failure on exitCode in both handleMigrate and handleTransform (pkale comments #2, #3, #4) - Add CLI integration tests for unfixable SQL (DROP CONSTRAINT), fixable SQL (FK + index), and prisma migrate diff pipe workflow (pkale comment #6) - Remove VARCHAR(30) assertion from workflow test (pkale comment #7) - Remove false claim about prebuilt binaries in README
Replace hand-maintained Prisma schema checks (autoincrement, Serial types, fulltext indexes, ID field hints) with dsql-lint's lint mode. The validator now: 1. Checks relationMode = "prisma" (Prisma-specific, can't be caught via SQL) 2. Generates SQL via `prisma migrate diff --from-empty` 3. Runs dsql-lint on the generated SQL to catch all incompatibilities This means the validator no longer needs manual updates when DSQL adds or removes feature support — dsql-lint is the single source of truth for SQL compatibility rules. The dsql-migrate command skips the SQL lint step (skipSqlLint option) since its transform step (dsql-lint --fix) already handles those issues.
Contributor
Author
|
Closing — recreating on a clean branch to avoid merge conflicts from the already-merged PR #401. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
autoincrement(),@db.Serial,@db.SmallSerial,@db.BigSerial,@@fulltext,Int @id,BigInt @id, andgen_random_uuid()without@db.Uuid. These are all removed.prisma migrate diffand runsdsql-linton the output to catch all SQL incompatibilities. This means the validator no longer needs manual updates when DSQL adds or removes feature support — dsql-lint is the single source of truth.relationMode = "prisma"remains as a Prisma-level check since it cannot be detected via SQL generation.dsql-migrateskips the SQL lint step (skipSqlLintoption) since its transform step (dsql-lint --fix) already handles those issues.Net: -269 lines, +68 lines across validator, tests, and README.
Test plan
validatecommand catches SERIAL (from autoincrement) via dsql-lintvalidatecommand catches CREATE INDEX without ASYNC via dsql-lintvalidatecommand reports missingrelationMode = "prisma"validatepasses for DSQL-compatible schema (no indexes, UUID IDs)dsql-migratesucceeds end-to-end (skips SQL lint, transform fixes issues)dsql-migratefails on missingrelationMode