This commit is contained in:
@@ -68,7 +68,10 @@ def create_all_tables() -> None:
|
|||||||
collection.ShoutCollection, # Зависит от Collection и Shout
|
collection.ShoutCollection, # Зависит от Collection и Shout
|
||||||
]
|
]
|
||||||
|
|
||||||
with local_session() as session:
|
from storage.db import engine
|
||||||
|
|
||||||
|
# Используем одно соединение для всех таблиц, чтобы избежать проблем с транзакциями
|
||||||
|
with engine.connect() as connection:
|
||||||
for model in models_in_order:
|
for model in models_in_order:
|
||||||
try:
|
try:
|
||||||
# Ensure model is a type[DeclarativeBase]
|
# Ensure model is a type[DeclarativeBase]
|
||||||
@@ -76,7 +79,7 @@ def create_all_tables() -> None:
|
|||||||
logger.warning(f"Skipping {model} - not a DeclarativeBase model")
|
logger.warning(f"Skipping {model} - not a DeclarativeBase model")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
create_table_if_not_exists(session.get_bind(), model) # type: ignore[arg-type]
|
create_table_if_not_exists(connection, model) # type: ignore[arg-type]
|
||||||
# logger.info(f"Created or verified table: {model.__tablename__}")
|
# logger.info(f"Created or verified table: {model.__tablename__}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
table_name = getattr(model, "__tablename__", str(model))
|
table_name = getattr(model, "__tablename__", str(model))
|
||||||
|
|||||||
Reference in New Issue
Block a user