Skip to content

feat(prisma): replace custom SQL transform with dsql-lint#401

Merged
amaksimo merged 6 commits into
mainfrom
replace-prisma-cli-with-dsql-lint
Apr 27, 2026
Merged

feat(prisma): replace custom SQL transform with dsql-lint#401
amaksimo merged 6 commits into
mainfrom
replace-prisma-cli-with-dsql-lint

Conversation

@amaksimo

Copy link
Copy Markdown
Contributor

Summary

  • Replace ~450 lines of custom SQL parsing/transformation in transform.ts with dsql-lint from aurora-dsql-tools
  • Add dsql-lint.ts utility for binary resolution (DSQL_LINT_PATH env var, then PATH)
  • Add lint CLI subcommand for checking SQL without applying fixes
  • Clean dsql-lint stderr output so users see diagnostic messages without temp file paths
  • Keep Prisma schema validator (validate.ts) unchanged — dsql-lint operates on SQL, not .prisma files

dsql-lint covers significantly more DSQL rules than the old custom code: SERIAL types, JSON/JSONB, arrays, TEMPORARY tables, triggers, PARTITION BY, sequences, CACHE validation, multi-DDL transaction splitting, and more.

Test plan

  • 47 unit/integration tests pass (up from 41 — 6 new tests added)
  • Verify npm run dsql-migrate -- prisma/schema.prisma -o migration.sql produces valid output
  • Verify npm run dsql-lint migration.sql detects issues
  • Verify npm run dsql-transform input.sql -o output.sql applies fixes
  • Verify stdin piping: cat input.sql | npm run dsql-transform
  • Verify helpful error when dsql-lint binary is not found
  • CI: ensure dsql-lint binary is available (via cargo install dsql-lint or DSQL_LINT_PATH)

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.
@amaksimo amaksimo requested a review from a team as a code owner April 24, 2026 18:49
@amaksimo amaksimo marked this pull request as draft April 24, 2026 18:52
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
@amaksimo amaksimo marked this pull request as ready for review April 27, 2026 17:28
Comment thread node/prisma/src/cli/index.ts
Comment thread node/prisma/src/cli/index.ts
Comment thread node/prisma/src/cli/index.ts
Comment thread node/prisma/test/cli-integration.test.ts
Comment thread node/prisma/test/cli-integration.test.ts
Comment thread node/prisma/test/workflow.test.ts Outdated

@pkale pkale left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments

- 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
@amaksimo amaksimo merged commit 83139de into main Apr 27, 2026
22 checks passed
@amaksimo amaksimo deleted the replace-prisma-cli-with-dsql-lint branch April 27, 2026 20:43
amaksimo added a commit that referenced this pull request Apr 28, 2026
## Summary

Bump version to 0.1.1 for release.

### Changes since v0.1.0

- **Replace custom SQL transform with dsql-lint** (#401) — SQL
transformation and linting now use `dsql-lint` instead of hand-written
regex rules
- **Delegate validator checks to dsql-lint** (#412) — Schema validation
generates SQL and runs `dsql-lint` in lint mode instead of maintaining
custom checks
- **Reject unknown CLI flags** (#413) — All commands now error on
unrecognized flags instead of silently ignoring them

## Test plan

- [x] All 60 tests pass
- [x] After merge, tag `node/prisma/v0.1.1` and push to trigger npm
publish
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.

2 participants