Skip to content

[DOCS]: Add documentation on how to set custom table constraints #4939

@julioz

Description

@julioz

Enhancement hasn't been filed before.

  • 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 , 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. In SQL terms, this would be it:

#
# ... 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions