Skip to content

refactor(prisma): delegate validator checks to dsql-lint#411

Closed
amaksimo wants to merge 7 commits intomainfrom
replace-prisma-cli-with-dsql-lint
Closed

refactor(prisma): delegate validator checks to dsql-lint#411
amaksimo wants to merge 7 commits intomainfrom
replace-prisma-cli-with-dsql-lint

Conversation

@amaksimo
Copy link
Copy Markdown
Contributor

Summary

  • Replace hand-maintained Prisma schema checks with dsql-lint's lint mode. The validator previously had custom regex checks for autoincrement(), @db.Serial, @db.SmallSerial, @db.BigSerial, @@fulltext, Int @id, BigInt @id, and gen_random_uuid() without @db.Uuid. These are all removed.
  • The validator now generates SQL via prisma migrate diff and runs dsql-lint on 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.
  • Only relationMode = "prisma" remains as a Prisma-level check since it cannot be detected via SQL generation.
  • dsql-migrate skips the SQL lint step (skipSqlLint option) since its transform step (dsql-lint --fix) already handles those issues.

Net: -269 lines, +68 lines across validator, tests, and README.

Test plan

  • validate command catches SERIAL (from autoincrement) via dsql-lint
  • validate command catches CREATE INDEX without ASYNC via dsql-lint
  • validate command reports missing relationMode = "prisma"
  • validate passes for DSQL-compatible schema (no indexes, UUID IDs)
  • dsql-migrate succeeds end-to-end (skips SQL lint, transform fixes issues)
  • dsql-migrate fails on missing relationMode
  • All 51 tests pass

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.
@amaksimo amaksimo requested a review from a team as a code owner April 27, 2026 21:31
@amaksimo
Copy link
Copy Markdown
Contributor Author

Closing — recreating on a clean branch to avoid merge conflicts from the already-merged PR #401.

@amaksimo amaksimo closed this Apr 27, 2026
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.

1 participant