SpecialistOff.NET / Вопросы / Статьи / Фрагменты кода / Резюме / Метки / Помощь / Файлы
НазадМетки: [alembic]; [sqlalchemy]; [python];
--- migration.py
#!/usr/bin/env python
from pathlib import Path
from alembic import command, config
from sqlalchemy.engine import create_engine
from helpers.yaml import yaml_read
def handle_migrate(args):
config_file = Path(args.config)
if config_file.exists():
params = yaml_read(config_file)
engine = create_engine(
params['sqlalchemy.url'],
echo=params['sqlalchemy.debug']
)
cfg = config.Config("alembic.ini")
with engine.begin() as connection:
cfg.attributes['connection'] = connection
command.upgrade(cfg, "head")