Fixed sql alchemy reset order. (#383)

There was a problem on the PG variant.
The SQLite variant worked. Now resetting properly also on PG.
This commit is contained in:
Philipp Horstenkamp 2023-11-14 17:44:24 +01:00 committed by GitHub
parent 7c1fac28fd
commit 119a3edfca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,13 +26,16 @@ def reset_tables(db: Session, all_tables: bool = False) -> None:
db.commit()
else:
logger.info(f"Resetting the main SQL tables in {db.bind}.")
for table in Base.metadata.sorted_tables:
if str(table) == entities.MissingCompany.__tablename__:
continue
logger.debug(f"Dropping {table}")
table.drop(db.bind)
db.commit()
tables = [
table
for table in Base.metadata.sorted_tables
if str(table) != entities.MissingCompany.__tablename__
]
logger.debug(f"Dropping tables: {', '.join([str(_) for _ in tables])}")
Base.metadata.drop_all(db.bind, tables=tables)
db.commit()
init_db(db)
db.commit()
def cli() -> None: