feat: add drop constraint if exists to compiler#8161
Conversation
48ebf75 to
8c25dad
Compare
|
this looks like the general idea, I wonder though since "IF EXISTS" / " IF NOT EXISTS" is generic enough that it should be in the base compiler (makes the PR even easier then). It looks like the base compiler is already doing "CASCADE" which certainly isn't covered by most backends either. |
|
youd add a few tests to test/sql/test_constraints in that case, compile tests similar to test_render_drop_constraint_cascade |
|
Thanks! I thought about that first, but then backed out, since it seemed dialect-specific and didn't want to break any compiler rules. Will re-work the change. |
|
this one is a gray area. we like to do only "SQL Standard " things in Core but I dont think create/drop of constraints is part of SQL standard anyway. the main thing is i think if someone does "if_exists" and runs it on a backend that doesnt support it, it should fail, otherwise why did they add "if_exists". so by just running that SQL, if the backend doesnt support it, we get that error for free. been making this kind of choice for about 17 years now... |
3ee6a1f to
ca90184
Compare
|
Thanks for the pointers - I've moved the code around to the base compiler, and rewrote the test to be similar to other tests in the module. I did some more reading of the Postgres docs, and it seems that the only constraint operation that supports the EXISTS behavior is drop constraint, so no need to implement the ADD side. Let me know what you think! |
ca90184 to
659dc57
Compare
drop constraint if exists to postgresdrop constraint if exists to compiler
Add `DROP CONSTRAINT ... IF EXISTS` behavior to the compiler. Fixes sqlalchemy#8141 Signed-off-by: Mike Fiedler <miketheman@gmail.com>
659dc57 to
120171a
Compare
| drop.if_exists and "IF EXISTS " or "", | ||
| formatted_name, | ||
| drop.cascade and " CASCADE" or "", |
There was a problem hiding this comment.
these could be replaced with inline if-else (these probably date back to a python version that did not yet support it )
There was a problem hiding this comment.
Thanks! I tried to remain consistent with the existing patterns rather than diverge for my changes.
Origin of this pattern cfa1a42
If it’s desirable to convert to newer patterns, happy to do so!
There was a problem hiding this comment.
not really required, but I think it's safe to convert to the new syntax since we are modifying this part anyway.
If you make the change, could you also add a changelog for this pr?
There was a problem hiding this comment.
Changes updated.
Changelog added as well - wasn't really certain if the location (2.0) and tags we correct - I was basing it off the opened ticket labels.
sqla-tester
left a comment
There was a problem hiding this comment.
OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 120171a of this pull request into gerrit so we can run tests and reviews and stuff
|
New Gerrit review created for change 120171a: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3970 |
Use single-line ternary if/else introduced in Python 2.5. Signed-off-by: Mike Fiedler <miketheman@gmail.com>
Signed-off-by: Mike Fiedler <miketheman@gmail.com>
sqla-tester
left a comment
There was a problem hiding this comment.
OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 43276e2 of this pull request into gerrit so we can run tests and reviews and stuff
|
Patchset 43276e2 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3970 |
|
@zzzeek I'm not super familiar with the code review process for sqlalchemy, and having read the docs, I'm not sure if there's another action I'm meant to take? |
|
Currently just wait for a review :) |
|
Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3970 has been merged. Congratulations! :) |
Description
Add
DROP CONSTRAINT ... IF EXISTSbehavior to the compiler.Fixes #8141
Checklist
This pull request is:
must include a complete example of the issue. one line code fixes without an
issue and demonstration will not be accepted.
Fixes: #<issue number>in the commit messageinclude a complete example of how the feature would look.
Fixes: #<issue number>in the commit messageHave a nice day!