consbio / pg-database-utils

A suite of utilities for PostgreSQL database queries and operations built on sqlalchemy
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Add CASCADE option for drop_table #3

Open dharvey-consbio opened 4 years ago

dharvey-consbio commented 4 years ago

Not as simple as it may seem. Requires something like:

from sqlalchemy.ext.compiler import compiles
from sqlalchemy.schema import DropTable

@compiles(DropTable, "postgresql")
def _compile_drop_table(element, compiler, **kwargs):
    return compiler.visit_drop_table(element) + " CASCADE"

https://stackoverflow.com/questions/38678336/sqlalchemy-how-to-implement-drop-table-cascade