mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
feat: Adds helper functions for migrations (#31303)
This commit is contained in:
@@ -19,10 +19,8 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects.sqlite.base import SQLiteDialect # noqa: E402
|
||||
from sqlalchemy.engine.reflection import Inspector
|
||||
|
||||
from superset.migrations.shared.utils import has_table
|
||||
from superset.utils.core import generic_find_fk_constraint_name
|
||||
|
||||
|
||||
@@ -73,23 +71,3 @@ 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 if it exist and the database
|
||||
is not sqlite.
|
||||
|
||||
:param table_name: The table name to drop foreign key constraints for
|
||||
"""
|
||||
connection = op.get_bind()
|
||||
inspector = Inspector.from_engine(connection)
|
||||
|
||||
if isinstance(connection.dialect, SQLiteDialect):
|
||||
return # sqlite doesn't like constraints
|
||||
|
||||
if has_table(table_name):
|
||||
foreign_keys = inspector.get_foreign_keys(table_name)
|
||||
|
||||
for fk in foreign_keys:
|
||||
op.drop_constraint(fk["name"], table_name, type_="foreignkey")
|
||||
|
||||
Reference in New Issue
Block a user