fix: Downgrade of revision 678eefb4ab44 throws error (#29799)

This commit is contained in:
Michael S. Molina 2024-08-01 08:10:08 -03:00 committed by GitHub
parent 2cbd945692
commit 249f5ec31a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -71,3 +71,17 @@ def redefine(
ondelete=on_delete,
onupdate=on_update,
)
def drop_fks_for_table(table_name: str) -> None:
"""
Drop all foreign key constraints for a table.
:param table_name: The table name to drop foreign key constraints for
"""
connection = op.get_bind()
inspector = Inspector.from_engine(connection)
foreign_keys = inspector.get_foreign_keys(table_name)
for fk in foreign_keys:
op.drop_constraint(fk["name"], table_name, type_="foreignkey")

View File

@ -30,6 +30,8 @@ import sqlalchemy as sa # noqa: E402
from alembic import op # noqa: E402
from sqlalchemy_utils import EncryptedType # noqa: E402
from superset.migrations.shared.constraints import drop_fks_for_table # noqa: E402
def upgrade():
op.create_table(
@ -80,5 +82,6 @@ def upgrade():
def downgrade():
drop_fks_for_table("database_user_oauth2_tokens")
op.drop_index("idx_user_id_database_id", table_name="database_user_oauth2_tokens")
op.drop_table("database_user_oauth2_tokens")