Skip to content
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

unique vs dropUnique inconsistency when using predicate #6036

Open
atlanteh opened this issue Mar 14, 2024 · 0 comments
Open

unique vs dropUnique inconsistency when using predicate #6036

atlanteh opened this issue Mar 14, 2024 · 0 comments

Comments

@atlanteh
Copy link

Environment

Knex version: 3.0.1
Database + version: postgres
OS: all

Bug

  1. Explain what kind of behaviour you are getting and how you think it should do
    When creating and dropping a unique constraint with a predicate the api doesn't behave the same way

  2. Error message

  3. Reduced test code, for example in https://npm.runkit.com/knex or if it needs real
    database connection to MySQL or PostgreSQL, then single file example which initializes
    needed data and demonstrates the problem.

knex.schema.table('my_table', (table) => {
    table.unique(['my_column'], {predicate: knex.whereRaw('"my_column" IS NOT NULL')})
});

Results in

create unique index "my_table_my_column_unique" on "my_table" ("my_column")
where
  "my_column" IS NOT NULL

And

knex.schema.table('my_table', (table) => {
    table.dropUnique(['my_column'])
})

results in

alter table "my_table"
drop constraint "my_table_my_column_unique"

which fails because there's no constraint, but an index by the name of "my_table_my_column_unique"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant