-
Notifications
You must be signed in to change notification settings - Fork 13.7k
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
fix: pass if table is already removed on upgrade #30017
Merged
sadpandajoe
merged 3 commits into
apache:master
from
preset-io:joe/check-for-table-before-dropping
Sep 3, 2024
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,14 @@ | |
|
||
def upgrade(): | ||
connection = op.get_bind() | ||
if connection.dialect.name != "sqlite": | ||
drop_fks_for_table("sl_columns") | ||
op.drop_table("sl_columns") | ||
|
||
try: | ||
if connection.dialect.name != "sqlite": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also seems like the special handling for sqlite could be handled within |
||
drop_fks_for_table("sl_columns") | ||
op.drop_table("sl_columns") | ||
except sa.exc.NoSuchTableError: | ||
# Table doesn't exist, so we can safely ignore this error | ||
pass | ||
|
||
|
||
def downgrade(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sadpandajoe Would you mind adding a method called
has_table
to https://github.com/apache/superset/blob/master/superset/migrations/shared/utils.py to be reused in these and future migrations?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, and/or change
drop_fks_for_table
to receive afail_when_missing=False
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we updated
drop_fks_for_table
we'd have to write something to drop table too, else it'll fail won't it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever makes sense, maybe
drop_table(table_name, including_fks=[], only_if_it_exists=True)
or maybe it's for another PR, but a common issue is a migration that fails at step 2 and when you rerun it it fails at step one since step one can only run once (say a create table). Personally think we could use more of the "drop-table-but-only-if-it-exists" and "create-table-but-drop-it-first-if-it-exists" type utils to avoid getting people tangled up. We've had many people open issue with the message of "step 1 one of the migration fails, here's the stacktrace", only to realize that the issue was with a subsequent step.