drizzle-team / drizzle-team/drizzle-orm
[DOCS]: Add documentation on how to set custom table constraints
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Enhancement hasn't been filed before.
- [x] I have verified this enhancement I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
Besides the already supported [typical table constraints ](https://orm.drizzle.team/docs/indexes-constraints), we model our schema to also verify violations to business rules, up to some extent.
An example is a table modeling a "calendar with events". There, I want to write a constraint that prevents multiple events from overlapping. That relies on a [PostgreSQL extension](https://www.postgresql.org/docs/current/btree-gist.html). In SQL terms, this would be it:
```sql
#
# ... my table creation ...
#
CREATE EXTENSION IF NOT EXISTS btree_gist;
ALTER TABLE "public"."talent_availability_block" ADD CONSTRAINT "ex_no_overlap" EXCLUDE USING gist ("availability_day_id" WITH =, int4range("start_minute", "end_minute") WITH &&);
```
How can we use the typescript bindings on the Drizzle schema to model such a constraint? I couldn't find an example in the documentation, so had to manually edit the generated SQL for the migration. This isn't ideal since my Drizzle schema file now represents only _partially_ the full extent of my table definition. Is it even possible to do it?
Contributor guide
Assessment
This issue has not been assessed yet.