K
Kyselyโ€ข3w ago
mike

Deferrable on unique indexes and constraints

Hi everyone, I am trying to figure out how to add deferrable to indexes and constraints in psql dialect. I've found some issues (such as issue 224) however not found any related to what I need:
CREATE UNIQUE INDEX active_cars
ON "Licenses" ("producer", "brand")
WHERE "active" = true AND "depracted" = false
DEFERRABLE INITIALLY DEFERRED;
CREATE UNIQUE INDEX active_cars
ON "Licenses" ("producer", "brand")
WHERE "active" = true AND "depracted" = false
DEFERRABLE INITIALLY DEFERRED;
I have not found any related builders neither in .addIndex nor .addUniqueConstraint.
GitHub
Issues ยท kysely-org/kysely
A type-safe TypeScript SQL query builder. Contribute to kysely-org/kysely development by creating an account on GitHub.
7 Replies
koskimas
koskimasโ€ข3w ago
Deferrable constraints can be added like this https://kyse.link/gR5ME AFAIK postgres indexes can't be deferred. Please point me to the docs that say otherwise if they can
mike
mikeOPโ€ข3w ago
thanks! you are right. I misused the question. deferrable constraint was what I was looking for. partial indexes (using where) are also supported?
koskimas
koskimasโ€ข3w ago
Yes https://kyse.link/T2EJS Although the need for sql there is a bit annoying
mike
mikeOPโ€ข3w ago
yeah, it is ๐Ÿ™‚ that's why I created a "helper" to make all these things easier ๐Ÿ™‚
No description
koskimas
koskimasโ€ข3w ago
Ugh, how is that better ๐Ÿ˜…
mike
mikeOPโ€ข3w ago
not this particular case ๐Ÿ˜„ however the helper is really very very very useful in migrations. it keeps all things type-safe and add missing-yet features in kysely
mike
mikeOPโ€ข3w ago
Few screenshots to give you some idea what the helper is all about. It's a framework on top of a framework ๐Ÿ™‚
No description
No description
No description
No description

Did you find this page helpful?