knex
knex copied to clipboard
Feature request: partial index inside unique method
Environment
Knex version: 0.95.14 Database + version: postgres 12.5 OS: mac
Feature discussion / request
I saw that there is this feature request created #2525 but was closed. I have also checked that this PR #2401 add predicate options only for .index method. As postgres supports the unique partial index, is it possible to add the predicate inside the .unique method too?
For the time being I have this working using this syntax:
await knex.schema.raw(
`CREATE UNIQUE INDEX "unique_partial_idx_userId_deleted" ON "users" ("userId", "deleted") WHERE "deleted" IS NOT TRUE`
);
I would prefer something like this would work, but it throws an error
table.index(['userId', 'deleted'], 'idx_userId_deleted', {
indexType: 'UNIQUE',
storageEngineIndexType: 'hash',
predicate: knex.whereNot('deleted', true)
});
We have a desire for this too. We have to use knex.raw, and to make a partial index requires basically reimplementing the where functions that knex already has ourselves.