feat: add support for DBML Checks block syntax - #47
Open
frenzzy wants to merge 3 commits into
Open
Conversation
Add parser support for the Checks block introduced in the official DBML specification. This allows parsing DBML files generated by @dbml/cli sql2dbml that include CHECK constraint definitions. Changes: - Add Checks, ChecksList, CheckItem grammar rules to dbml.pegjs - Add TableChecks Zod schema to types.ts - Add checks extraction to checker.ts The implementation follows the existing Indices block pattern exactly. Checks are parsed and stored in the AST but not rendered visually (same as index details) since they are constraint metadata. Fixes parsing errors like: Could not parse input at line X. Expected "'", "'''", "\"", or whitespace but "`" found. References: - DBML Checks syntax: https://dbml.dbdiagram.io/docs/#checks-definition - @dbml/core Checks support: holistics/dbml@9dc6e17 Co-Authored-By: Claude <noreply@anthropic.com>
Reset generated files to origin/main and regenerate with proper Prettier formatting to minimize diff for easier code review. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add test example covering various Checks block scenarios: - Simple check constraints (price > 0) - Named checks with settings [name: 'constraint_name'] - Complex expressions with AND/OR logic - Multiple checks per table - Checks combined with indexes and references This adds 4 new tests (100 → 104 total) to prevent future regressions in Checks parsing. Co-Authored-By: Claude <noreply@anthropic.com>
Author
|
While waiting for this PR to be merged, I've published a temporary fork to npm: Package: @frenzzy/dbml-renderer Usage# Using npx
npx @frenzzy/dbml-renderer@checks -i schema.dbml -o schema.svg
# Or install as dependency
npm install @frenzzy/dbml-renderer@checksThis is a drop-in replacement until the official package is updated. |
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.
Fixes #49
Summary
Add parser support for the DBML
Checksblock syntax, which was introduced in the official DBML specification (v5.0.0). This allows parsing DBML files generated by@dbml/cli sql2dbmlthat include CHECK constraint definitions.Problem
When using
sql2dbmlto convert PostgreSQL schemas that contain CHECK constraints, the generated DBML includesChecksblocks:This causes dbml-renderer to fail with:
Solution
Added parser support following the existing
Indicesblock pattern:Grammar (
src/dbml.pegjs)Types (
src/types.ts)Checker (
src/checker.ts)checksproperty toNormalizedTableextract()helperImplementation Notes
Indicespattern for consistencyChecksblocksTest Coverage
Added
examples/checks.dbmltest file covering:price > 0)[name: 'constraint_name'])Test count: 100 → 104 (4 new tests added)
References
Test Plan
npm run format:checkpassesnpm run buildpassesChecksblocksChecks