-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
"drop constraint if exists" unavailable #2167
Comments
@andrei-pmbcn have you any API in mind how it would work consistently with other knex schema building APIs? If this is a feature request, please write it as one and add some proposal how the feature should work. |
For consistency... QueryBuilder API .dropTable()
.dropTableIfExists() SchemaBuilder API .dropForeign()
.dropForeignIfExists()
.dropUnique()
.dropUniqueIfExists()
.dropPrimary()
.dropPrimaryIfExists() |
@wubzz I suppose you meant schema builder API and column builder API? Looks good though. Edit: fixed typo meat -> meant 😆 |
@elhigu Err awkward.. Yes that is what I meant. :) |
Any movement on this? |
@alechirsch Noone is actively working on it. PRs are welcome! |
I might look into it if I have time, I just ran into needing this feature. Using raw for now. |
For anyone looking for the raw command:
This is for Postgres and MariaDB. Might need altering for other dbms. |
This works for MariaDB, but not for MySQL. Haven't tested others. |
any updates on this? can I contribute somehow if it is not yet implemented? |
@cod3cod3 yup, PR is welcome! |
Took a crack at this, it seems pretty straightforward? If this looks right I can do the same for dropForeign and dropPrimary and add tests as well. |
@kibertoad Does this look like the right direction? |
Based on the documentation, there seems to be no way of including an "IF EXISTS" condition when dropping constraints such as foreign keys, so "ALTER TABLE 'x' DROP CONSTRAINT IF EXISTS 'x_y_foreign' ", for instance, can only be done using a raw string. Moreover, a "table.raw" method does not exist, so one has to make the entire ALTER TABLE statement raw. This can be a pretty awkward problem when running scripts that generate schemas. A convoluted workaround is available using whereExists, but it would be ideal if table.foreign etc had an argument to include the "IF EXISTS" condition.
The text was updated successfully, but these errors were encountered: