Skip to content

Commit

Permalink
Delete the public DB schema directly
Browse files Browse the repository at this point in the history
Extracted from #188
as a separate PR.
  • Loading branch information
seanh committed Jan 17, 2025
1 parent 69a1a77 commit 5849a0e
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ def delete(engine: Engine) -> None:
else:
pre_delete(engine)

Base.metadata.drop_all(engine)
with engine.connect() as connection:
# Delete the DB's "public" schema directly.
# We do this instead of using SQLAlchemy's drop_all() because we want
# to delete *all* tables in the DB, not just the ones that SQLAlchemy
# knows about from the current codebase.
# For example this will delete tables created by migrations in other
# branches.
connection.execute(text("DROP SCHEMA PUBLIC CASCADE;"))
connection.execute(text("CREATE SCHEMA PUBLIC;"))
connection.execute(text("COMMIT;"))

try:
from {{ cookiecutter.package_name }}.db import post_delete
Expand Down

0 comments on commit 5849a0e

Please sign in to comment.