Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support if_exists / if_not_exists on drop_table and create_table operations #1520

Closed
agriffin-grow opened this issue Aug 14, 2024 · 6 comments
Labels
command interface use case not quite a feature and not quite a bug, something we just didn't think of

Comments

@agriffin-grow
Copy link
Contributor

agriffin-grow commented Aug 14, 2024

Describe the use case
This is similar to #524, which appears to at least be implemented for indexes.

SqlAlchemy already supports these operations on DropTable and CreateTable so this would essentially be a pass-through in a similar manner.

Databases / Backends / Drivers targeted

Postgresql

Example Use
Much like drop_index, I'd expect

op.drop_table('foobar', if_exists=True)

to produce

DROP TABLE IF EXISTS foobar

Additional context
This is just some insurance for edge cases where a migration partially applies due to external circumstances. i.e. a migration containing two drop_table operations could fail after the first succeeds, but then would require some surgery to work again

Have a nice day!

@agriffin-grow agriffin-grow added requires triage New issue that requires categorization use case not quite a feature and not quite a bug, something we just didn't think of labels Aug 14, 2024
@CaselIT CaselIT added command interface and removed requires triage New issue that requires categorization labels Aug 14, 2024
@CaselIT
Copy link
Member

CaselIT commented Aug 14, 2024

Hi,

I was convinced it was already supported, but it seems not.

A PR with an initial implementation would be appreciated!

@agriffin-grow
Copy link
Contributor Author

@CaselIT #1521

Hope that's everything

@agriffin-grow
Copy link
Contributor Author

@CaselIT - do you know when we could expect this to get merged and released?

@CaselIT
Copy link
Member

CaselIT commented Aug 23, 2024

sorry, been on holiday this past week. Will try taking a look in the weekend

@sqla-tester
Copy link
Collaborator

Aaron Griffin has proposed a fix for this issue in the main branch:

Support if_exists and if_not_exists on create/drop table commands https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5455

@CaselIT
Copy link
Member

CaselIT commented Sep 13, 2024

#1434 was a duplicate of this issue

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
command interface use case not quite a feature and not quite a bug, something we just didn't think of
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants