Skip to content

Feat: Support check constraint#765

Merged
huydo862003 merged 44 commits intomasterfrom
feat/dbml-parse/support-check-constraint
Oct 23, 2025
Merged

Feat: Support check constraint#765
huydo862003 merged 44 commits intomasterfrom
feat/dbml-parse/support-check-constraint

Conversation

@huydo862003
Copy link
Copy Markdown
Contributor

@huydo862003 huydo862003 commented Oct 14, 2025

Summary

  • dbml-parse:
    • Support constraint setting in table columns and tablepartial columns: a column can have multiple constraints.
          Table User {
                balance int [constraint: `balance > 0`, constraint: `balance < 100000000`]
          }
      
    • Support constraints element in table and tablepartial elements: A table can contain multiple constraints and a constraint can be named or nameless.
         Table User {
                balance int
                constraints {
                    `balance >= 0` [name: "balance_not_negative"]
                    `balance < 1000000000`
                }
         }
      
    • Constraints in TablePartial will be injected into the Table that injects the partial. Constraint names injected this way will be modified properly to avoid duplicate constraint names.
    • Support autocompletion related to constraints and constraint.
      • When inside a column setting, constraint would be suggested.
      • When inside a Table element, constraints would be suggested.
      • When inside a constraint setting, name would be suggested.
    • Function expressions (`expr`) can now contain newlines to better support complex conditions. Example:
          Table inventory {
              stock int
              status string
              constraints {
                 `CASE WHEN status = 'active' THEN stock
                             WHEN status = 'discontinued' THEN 0
                             ELSE 1
                   END >= 0`
              }
          }
      
    • Some minor bug fixes and refactors.
  • dbml-core:
    • Support constraints in model structure.
    • Support constraints in all parsers & exporters.
      • Support column's check constraints.
      • Support table definition's check constraints.
      • Support ALTER TABLE ADD CONSTRAINT.
    • Remove CONSTRAINT as plsql_unreserved_keyword from Postgres ANTLR grammar.
    • No longer support converting CHECK constraints into DBML ENUMs in MSSQL parser.
  • Not supported yet:
    • ALTER TABLE ALTER CONSTRAINT is not supported and is currently ignored when importing SQL.
    • ALTER TABLE DROP CONSTRAINT is not supported and is currently ignored when importing SQL.
    • ALTER TABLE RENAME CONSTRAINT is not supported.
    • Duplicate constraint names are allowed. We currently do not perform duplicate constraint names check.

Issue

#591
#484
#68

Lasting Changes (Technical)

(please list down: code changes/things that have wide-effect; new libraries/functions added that can be used by others; examples below)

  • (Added class EmailValidator to validate email address' validity)
  • (Added Tenant#is_trial? check)

Checklist

Please check directly on the box once each of these are done

  • Documentation (if necessary)
  • Tests (integration test/unit test)
  • Integration Tests Passed
  • Code Review

@huydo862003 huydo862003 marked this pull request as draft October 14, 2025 10:57
@huydo862003 huydo862003 changed the title Feat/dbml parse/support check constraint Feat: Support check constraint Oct 14, 2025
…for the constraint setting & rename and redefine some compiler error code
@huydo862003 huydo862003 force-pushed the feat/dbml-parse/support-check-constraint branch from a66c2ba to 0efe858 Compare October 15, 2025 03:00
@huydo862003 huydo862003 force-pushed the feat/dbml-parse/support-check-constraint branch 2 times, most recently from 3eb0625 to 100eba2 Compare October 15, 2025 14:47
@huydo862003 huydo862003 force-pushed the feat/dbml-parse/support-check-constraint branch from 40dccac to bfd364e Compare October 15, 2025 14:51
@huydo862003 huydo862003 force-pushed the feat/dbml-parse/support-check-constraint branch from ed7ab45 to 2ca4e97 Compare October 15, 2025 15:06
@huydo862003 huydo862003 marked this pull request as ready for review October 16, 2025 12:44
@huydo862003 huydo862003 force-pushed the feat/dbml-parse/support-check-constraint branch from cd5f8c7 to e5253d1 Compare October 22, 2025 06:27
Comment thread packages/dbml-core/src/parse/schemarb/parser.pegjs Outdated
Copy link
Copy Markdown
Collaborator

@huyphung1602 huyphung1602 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@NQPhuc NQPhuc left a comment

Choose a reason for hiding this comment

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

Please remember to update docs under dbml-homepage as well.

@NQPhuc NQPhuc added the PR: New Feature 🚀 A type of pull request used for changelog categories label Oct 23, 2025
@huydo862003 huydo862003 added the PR: Breaking Change 💥 A type of pull request used for changelog categories label Oct 23, 2025
@huydo862003 huydo862003 merged commit c06155f into master Oct 23, 2025
2 of 3 checks passed
@huydo862003 huydo862003 deleted the feat/dbml-parse/support-check-constraint branch October 23, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Breaking Change 💥 A type of pull request used for changelog categories PR: New Feature 🚀 A type of pull request used for changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants