GPQBot
39 строк · 1.1 Кб
1import pathlib2import sys3from logging.config import fileConfig4
5from alembic import context6from sqlalchemy import engine_from_config, pool7
8# Import models to make them visible by alembic
9
10# init config
11sys.path.append(str(pathlib.Path(__file__).resolve().parents[3]))12
13# Imports from `app` should go after `path` patch
14from app.settings import settings # isort:skip15from app.db.sqlalchemy import Base, make_url_sync # isort:skip16
17
18postgres_dsn = make_url_sync(settings.POSTGRES_DSN)19context_config = context.config20fileConfig(context_config.config_file_name)21target_metadata = Base.metadata22context_config.set_main_option("sqlalchemy.url", postgres_dsn)23
24
25def run_migrations_online() -> None:26connectable = engine_from_config(27context_config.get_section(context_config.config_ini_section),28prefix="sqlalchemy.",29poolclass=pool.NullPool,30)31
32with connectable.connect() as connection:33context.configure(connection=connection, target_metadata=target_metadata)34
35with context.begin_transaction():36context.run_migrations()37
38
39run_migrations_online()