Skip to content

Instantly share code, notes, and snippets.

@giuliano-macedo
Last active February 16, 2023 14:39
Show Gist options
  • Save giuliano-macedo/9fef9352395ccc4dc0304c23a5cdd3a9 to your computer and use it in GitHub Desktop.
Save giuliano-macedo/9fef9352395ccc4dc0304c23a5cdd3a9 to your computer and use it in GitHub Desktop.
sqlalchemy createtable with cascade (with type hints), original answer: https://stackoverflow.com/a/38679457/5133524
from sqlalchemy.schema import DropTable
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.dialects.postgresql.base import PGDDLCompiler
from typing import Any
@compiles(DropTable, "postgresql")
def _compile_drop_table(element: DropTable, compiler: PGDDLCompiler, **kwargs: Any) -> str:
return compiler.visit_drop_table(element) + " CASCADE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment