PillarTool/pillar_tool/db/__init__.py

26 lines
647 B
Python

import os
import alembic
from alembic.config import Config
from alembic.command import upgrade
from pillar_tool.util import config
from models import *
cfg = config()
user = cfg.db.user
password = cfg.db.password
host = cfg.db.host
port = cfg.db.port
database = cfg.db.database
alembic_cfg = Config()
alembic_cfg.set_main_option('script_location', f'{os.path.dirname(os.path.realpath(__file__))}/migrations')
alembic_cfg.set_main_option('sqlalchemy.url', f'postgres://{user}:{password}@{host}:{port}/{database}')
alembic_cfg.set_main_option('prepend_sys_path', '.')
def run_db_migrations():
upgrade(config=alembic_cfg, revision='head')