fix: update schedule

This commit is contained in:
jfmcarreira committed 2026-10-06 01:44:50 +01:00
1 parent 7147086e84
commit 2c3e038161
19 files changed
+623 -27

No files matched your search

+38 -1
View File
@@ -1,12 +1,19 @@
from __future__ import annotations
from collections.abc import Generator
from pathlib import Path
from sqlalchemy import create_engine
from alembic import command
from alembic.config import Config
from alembic.runtime.migration import MigrationContext
from alembic.script import ScriptDirectory
from sqlalchemy import create_engine, inspect
from sqlalchemy.orm import DeclarativeBase, Session, sessionmaker
from .config import settings
MIGRATIONS_DIR = Path(__file__).resolve().parent.parent / "migrations"
class Base(DeclarativeBase):
pass
@@ -17,6 +24,36 @@ engine = create_engine(settings.database_url, connect_args=connect_args, future=
SessionLocal = sessionmaker(bind=engine, autoflush=False, expire_on_commit=False, class_=Session)
def alembic_config() -> Config:
config = Config(str(MIGRATIONS_DIR.parent / "alembic.ini"))
config.set_main_option("script_location", str(MIGRATIONS_DIR))
config.set_main_option("sqlalchemy.url", settings.database_url)
return config
def run_migrations() -> None:
"""Bring the database up to the latest revision. Safe to call on every start."""
command.upgrade(alembic_config(), "head")
def current_revision() -> str | None:
with engine.connect() as connection:
return MigrationContext.configure(connection).get_current_revision()
def has_tables() -> bool:
"""True when the database already holds the pre-Alembic schema."""
return bool(set(inspect(engine).get_table_names()) - {"alembic_version"})
def head_revision() -> str:
return ScriptDirectory.from_config(alembic_config()).get_current_head() or ""
def stamp(revision: str) -> None:
command.stamp(alembic_config(), revision)
def get_db() -> Generator[Session, None, None]:
db = SessionLocal()
try: