-
-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PG] Add Support For Domains and Check Constraints On Columns #4040
base: main
Are you sure you want to change the base?
Conversation
@AndriiSherman @dankochetov mind looking at this PR? Domain support was on the backlog for almost 2 years. I really want it :-) so I gave it a shot myself. |
Awesome! Will definitely check it |
Cmon man that rocks |
@AndriiSherman I put in all the remaining changes that I can foresee. There's a lot of new tests that hopefully cover everything. Would you mind giving it a review? Feel free to change anything you like. It would be fantastic if this could get into V1. |
This PR introduces PostgreSQL Domain Support and enhances Check Constraint Integration with Drizzle-Zod, addressing issues #218, #3446, and #3520.
Why this PR?
End the Validation Duplication Nightmare
Tired of maintaining duplicate validation logic? This PR eliminates the need to write the same rules in two places:
Database constraints (CHECK clauses, domains)
Application validation (Zod schemas, manual checks)
Before 😩
Now 🎉
Key Benefits 🌟
1. Single Source of Truth
Define validation rules once in your database schema - Drizzle automatically propagates them to Zod
2. DRY Principle Enforced
Never accidentally update application validation without updating database constraints (or vice versa)
3. Type Safety from Edge to Edge
Get Zod schemas that exactly match your database constraints, from API endpoints to UI forms
4. Schema Evolution Made Safe
Changing a constraint in your migration? Zod validations automatically update when you regenerate types
Real-World Impact 💸
For a medium-sized app with:
You'll eliminate 200-300 lines of manual Zod validation code and save 5-10 hours/month on schema maintenance.
Changes: PostgreSQL Domain Support
What are Domains?
Domains are user-defined data types that enforce constraints on existing PostgreSQL types. They help standardize column definitions and reuse validation rules across tables.
Defining Domains in Drizzle
Equivalent SQL:
Key Features
Changes: Check Constraint Integration with Drizzle-Zod
Automatic Zod Validation
Check constraints (both column-level and domain-based) now generate proper Zod validations:
Supported Constraints
TODOs