migrate-on-deploy
Some checks failed
Deploy on push / deploy (push) Failing after 7s

This commit is contained in:
2025-08-23 10:25:15 +03:00
parent 1b25738714
commit d33e53933f
2 changed files with 19 additions and 2 deletions

18
main.py
View File

@@ -210,6 +210,24 @@ async def lifespan(app: Starlette):
""" """
try: try:
print("[lifespan] Starting application initialization") print("[lifespan] Starting application initialization")
# Запускаем миграции Alembic перед созданием таблиц
print("[lifespan] Running database migrations...")
try:
import subprocess
result = subprocess.run(
["alembic", "upgrade", "head"],
capture_output=True,
text=True,
cwd="/app"
)
if result.returncode == 0:
print("[lifespan] Database migrations completed successfully")
else:
print(f"[lifespan] Warning: migrations failed: {result.stderr}")
except Exception as e:
print(f"[lifespan] Warning: could not run migrations: {e}")
create_all_tables() create_all_tables()
# Инициализируем RBAC систему с dependency injection # Инициализируем RBAC систему с dependency injection

View File

@@ -74,8 +74,7 @@ class Draft(Base):
authors = relationship(get_author_model(), secondary=DraftAuthor.__table__) authors = relationship(get_author_model(), secondary=DraftAuthor.__table__)
topics = relationship(Topic, secondary=DraftTopic.__table__) topics = relationship(Topic, secondary=DraftTopic.__table__)
# shout/publication # shout/publication - связь с опубликованной публикацией
# Временно закомментировано для совместимости с тестами
shout: Mapped[int | None] = mapped_column(ForeignKey("shout.id"), nullable=True) shout: Mapped[int | None] = mapped_column(ForeignKey("shout.id"), nullable=True)
__table_args__ = ( __table_args__ = (