mirror of https://github.com/apache/superset.git
fix: migration script can't drop constraint (#15807)
This commit is contained in:
parent
5cc95bb378
commit
6cb91ee142
|
@ -30,7 +30,7 @@ from flask_appbuilder import Model
|
||||||
from flask_migrate import downgrade, upgrade
|
from flask_migrate import downgrade, upgrade
|
||||||
from graphlib import TopologicalSorter # pylint: disable=wrong-import-order
|
from graphlib import TopologicalSorter # pylint: disable=wrong-import-order
|
||||||
from progress.bar import ChargingBar
|
from progress.bar import ChargingBar
|
||||||
from sqlalchemy import create_engine, inspect, Table
|
from sqlalchemy import create_engine, inspect
|
||||||
from sqlalchemy.ext.automap import automap_base
|
from sqlalchemy.ext.automap import automap_base
|
||||||
|
|
||||||
from superset import db
|
from superset import db
|
||||||
|
@ -172,7 +172,6 @@ def main(
|
||||||
rows = session.query(model).count()
|
rows = session.query(model).count()
|
||||||
print(f"- {model.__name__} ({rows} rows in table {model.__tablename__})")
|
print(f"- {model.__name__} ({rows} rows in table {model.__tablename__})")
|
||||||
model_rows[model] = rows
|
model_rows[model] = rows
|
||||||
session.close()
|
|
||||||
|
|
||||||
print("Benchmarking migration")
|
print("Benchmarking migration")
|
||||||
results: Dict[str, float] = {}
|
results: Dict[str, float] = {}
|
||||||
|
|
|
@ -28,6 +28,7 @@ down_revision = "96e99fb176a0"
|
||||||
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
from sqlalchemy.engine.reflection import Inspector
|
||||||
from sqlalchemy.exc import OperationalError
|
from sqlalchemy.exc import OperationalError
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,13 +120,17 @@ def upgrade():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def has_unique_constraint(constraint_name: str, table_name: str) -> bool:
|
||||||
|
bind = op.get_bind()
|
||||||
|
inspector = Inspector.from_engine(bind)
|
||||||
|
unique_constraints = inspector.get_unique_constraints(table_name)
|
||||||
|
return constraint_name in {constraint["name"] for constraint in unique_constraints}
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.drop_index(op.f("ix_report_schedule_active"), table_name="report_schedule")
|
op.drop_index(op.f("ix_report_schedule_active"), table_name="report_schedule")
|
||||||
try:
|
if has_unique_constraint("uq_report_schedule_name", "report_schedule"):
|
||||||
op.drop_constraint("uq_report_schedule_name", "report_schedule", type_="unique")
|
op.drop_constraint("uq_report_schedule_name", "report_schedule", type_="unique")
|
||||||
except Exception:
|
|
||||||
# Expected to fail on SQLite
|
|
||||||
pass
|
|
||||||
|
|
||||||
op.drop_table("report_execution_log")
|
op.drop_table("report_execution_log")
|
||||||
op.drop_table("report_recipient")
|
op.drop_table("report_recipient")
|
||||||
|
|
Loading…
Reference in New Issue