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

fix: drop check constraint on dbs to rename column #17275

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions superset/migrations/versions/b92d69a6643c_rename_csv_to_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,36 @@

import sqlalchemy as sa
from alembic import op
from sqlalchemy.engine.reflection import Inspector


def upgrade():
with op.batch_alter_table("dbs") as batch_op:
batch_op.alter_column(
"allow_csv_upload",
new_column_name="allow_file_upload",
existing_type=sa.Boolean(),
)
try:
with op.batch_alter_table("dbs") as batch_op:
batch_op.alter_column(
"allow_csv_upload",
new_column_name="allow_file_upload",
existing_type=sa.Boolean(),
)
except sa.exc.OperationalError:
# In MySQL 8.0 renaming the column rename fails because it has
# a constraint check; we can safely remove it in that case, see
# https://github.com/sqlalchemy/alembic/issues/699
bind = op.get_bind()
inspector = Inspector.from_engine(bind)
check_constraints = inspector.get_check_constraints("dbs")
for check_constraint in check_constraints:
if "allow_csv_upload" in check_constraint["sqltext"]:
name = check_constraint["name"]
op.drop_constraint(name, table_name="dbs", type_="check")

# try again
with op.batch_alter_table("dbs") as batch_op:
batch_op.alter_column(
"allow_csv_upload",
new_column_name="allow_file_upload",
existing_type=sa.Boolean(),
)


def downgrade():
Expand Down