mirror of
https://github.com/markbeep/AudioBookRequest.git
synced 2026-01-24 23:20:09 -06:00
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
import pathlib
|
|
from logging.config import fileConfig
|
|
|
|
from alembic import context
|
|
from app.internal import models
|
|
from app.internal.env_settings import Settings
|
|
from app.util.db import engine
|
|
|
|
# this is the Alembic Config object, which provides
|
|
# access to the values within the .ini file in use.
|
|
config = context.config
|
|
|
|
# Interpret the config file for Python logging.
|
|
# This line sets up loggers basically.
|
|
if config.config_file_name is not None:
|
|
fileConfig(config.config_file_name)
|
|
|
|
# add your model's MetaData object here
|
|
# for 'autogenerate' support
|
|
# from myapp import mymodel
|
|
# target_metadata = mymodel.Base.metadata
|
|
target_metadata = models.BaseModel.metadata
|
|
|
|
# other values from the config, defined by the needs of env.py,
|
|
# can be acquired:
|
|
# my_important_option = config.get_main_option("my_important_option")
|
|
# ... etc.
|
|
|
|
|
|
def run_migrations() -> None:
|
|
"""Run migrations in 'online' mode.
|
|
|
|
In this scenario we need to create an Engine
|
|
and associate a connection with the context.
|
|
|
|
"""
|
|
db_path = Settings().get_sqlite_path()
|
|
pathlib.Path(db_path).parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
with engine.connect() as connection:
|
|
context.configure(
|
|
connection=connection,
|
|
target_metadata=target_metadata,
|
|
render_as_batch=True,
|
|
)
|
|
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
run_migrations()
|