Skip to content

Commit a72cc8b

Browse files
committed
drop column with cascade
1 parent e9f5be0 commit a72cc8b

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

sqlalchemy_iris/alembic.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from alembic.ddl.base import Column
2020
from alembic.ddl.base import alter_table
2121
from alembic.ddl.base import alter_column
22+
from alembic.ddl.base import drop_column
2223
from alembic.ddl.base import format_type
2324
from alembic.ddl.base import format_column_name
2425
from .base import IRISDDLCompiler
@@ -73,22 +74,6 @@ def compare_server_default(
7374
rendered_inspector_default,
7475
)
7576

76-
def drop_column(
77-
self,
78-
table_name: str,
79-
column: Column,
80-
schema: Optional[str] = None,
81-
**kw,
82-
) -> None:
83-
column_name = column.name
84-
fkeys = self.dialect.get_foreign_keys(self.connection, table_name, schema)
85-
fkey = [
86-
fkey["name"] for fkey in fkeys if column_name in fkey["constrained_columns"]
87-
]
88-
if len(fkey) == 1:
89-
self._exec(_ExecDropForeignKey(table_name, fkey[0], schema))
90-
super().drop_column(table_name, column, schema, **kw)
91-
9277
def alter_column(
9378
self,
9479
table_name: str,
@@ -192,3 +177,11 @@ def visit_rename_column(element: ColumnName, compiler: IRISDDLCompiler, **kw) ->
192177
alter_column(compiler, element.column_name),
193178
format_column_name(compiler, element.newname),
194179
)
180+
181+
@compiles(DropColumn, "iris")
182+
def visit_drop_column(element: DropColumn, compiler: IRISDDLCompiler, **kw) -> str:
183+
return "%s %s CASCADE" % (
184+
alter_table(compiler, element.table_name, element.schema),
185+
drop_column(compiler, element.column.name, **kw),
186+
)
187+

0 commit comments

Comments
 (0)