Skip to content

Feat/dbml connector/support check constraints#766

Merged
huydo862003 merged 30 commits intomasterfrom
feat/dbml-connector/support-check-constraints
Oct 28, 2025
Merged

Feat/dbml connector/support check constraints#766
huydo862003 merged 30 commits intomasterfrom
feat/dbml-connector/support-check-constraints

Conversation

@huydo862003
Copy link
Copy Markdown
Contributor

@huydo862003 huydo862003 commented Oct 20, 2025

Summary

  • Continuation of Feat: Support check constraint #765.
  • Support extracting CHECK constraints in @dbml/connector.
  • Remove support of converting CHECK constraints into DBML ENUMs in MSSQL connector.
  • IMPORTANT: The MySQL connector currently generates malformed DBML when there's a check constraint in the SQL, because MySQL always store check constraints with quoted column names in backticks. For example, this:
     CHECK (`col` LIKE '%...%')
    
    would be transformed into
     constraint: ``col` LIKE '%...%'`
    
    which is erroneous. We have no proper way to workaround this as we currently do not support escaping inside function expressions.

Issue

(issue link here)

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 20, 2025 10:22
@huydo862003 huydo862003 force-pushed the feat/dbml-connector/support-check-constraints branch 11 times, most recently from fea1498 to bdee349 Compare October 22, 2025 09:01
@huydo862003 huydo862003 marked this pull request as ready for review October 22, 2025 09:27
@huydo862003 huydo862003 changed the base branch from feat/dbml-parse/support-check-constraint to master October 22, 2025 09:27
@huydo862003 huydo862003 force-pushed the feat/dbml-connector/support-check-constraints branch 3 times, most recently from 60451fa to 525d56a Compare October 23, 2025 10:18
@huydo862003 huydo862003 force-pushed the feat/dbml-connector/support-check-constraints branch from e3ebbf3 to 48759bd Compare October 28, 2025 05:01
@huydo862003 huydo862003 added the PR: New Feature 🚀 A type of pull request used for changelog categories label Oct 28, 2025
@huydo862003 huydo862003 changed the base branch from master to fix/change-constraint-to-check October 28, 2025 05:10
"updated_at" "timestamp on update CURRENT_TIMESTAMP" [default: `CURRENT_TIMESTAMP`]

Checks {
`(`price` > 0) and (`price` < 1000000)` [name: 'products_chk_1']
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please note that we currently do not escape ` inside function expression. Mysql always quote columns in backticks, so this is currently malformed DBML.

https://www.notion.so/holistics/TDD-72-Database-CHECK-constraint-in-DBML-28bf89dc7e49801fa8d3fb9cf25ca8de?source=copy_link#292f89dc7e498001bbfce3d92f74cdd4

Base automatically changed from fix/change-constraint-to-check to master October 28, 2025 07:08
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should add this related doc into this connector code as a comment em. You can also write some short notes for better understanding: https://www.notion.so/holistics/TDD-72-Database-CHECK-constraint-in-DBML-28bf89dc7e49801fa8d3fb9cf25ca8de#292f89dc7e498001bbfce3d92f74cdd4

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment thread packages/dbml-cli/__test__/cli.test.js Outdated
Comment thread packages/dbml-connector/src/connectors/postgresConnector.ts
Comment thread packages/dbml-connector/src/connectors/postgresConnector.ts
Comment thread packages/dbml-connector/src/connectors/mssqlConnector.ts
Comment thread packages/dbml-connector/src/connectors/mysqlConnector.ts
Comment thread packages/dbml-connector/src/connectors/mysqlConnector.ts
Comment thread packages/dbml-connector/src/connectors/postgresConnector.ts
@huydo862003 huydo862003 merged commit d585390 into master Oct 28, 2025
3 checks passed
@huydo862003 huydo862003 deleted the feat/dbml-connector/support-check-constraints branch October 28, 2025 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants