Files
Enclume/migrations/env.py
T
hcornet 5766e24213
build / Garde-fou (pull_request) Successful in 9m19s
build / Images Harbor (catalog-sync, Dockerfile.catalog-sync) (pull_request) Skipped
build / Images Harbor (web, Dockerfile) (pull_request) Skipped
build / Images Harbor (catalog-sync, Dockerfile.catalog-sync) (push) Successful in 9m45s
build / Garde-fou (push) Successful in 9m19s
build / Images Harbor (web, Dockerfile) (push) Successful in 13m10s
Alembic et le point d'entree lisent la configuration de l'application
2026-09-10 20:58:40 +02:00

55 lines
1.5 KiB
Python

"""Contexte Alembic.
L'URL vient de la configuration de l'application, jamais du fichier ini : la
meme image sert en developpement et en production, et le mot de passe est
encode au meme endroit pour tout le monde.
"""
from __future__ import annotations
import os
import sys
from alembic import context
from sqlalchemy import engine_from_config, pool
sys.path.insert(0, os.getcwd())
from enclume.config import Config
from enclume.db import Base
config = context.config
# Une seule source de verite pour l'URL : celle de l'application, qui sait
# assembler les elements separes et encoder le mot de passe.
config.set_main_option("sqlalchemy.url", Config.SQLALCHEMY_DATABASE_URI)
target_metadata = Base.metadata
def run_migrations_offline() -> None:
context.configure(
url=config.get_main_option("sqlalchemy.url"),
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()