Skip to content

Instantly share code, notes, and snippets.

@pingzh
Created February 10, 2021 06:54
Show Gist options
  • Save pingzh/80d4d002224c13f141b6b34be656273b to your computer and use it in GitHub Desktop.
Save pingzh/80d4d002224c13f141b6b34be656273b to your computer and use it in GitHub Desktop.
Run alembic command with code
from alembic.config import Config
from alembic import command
def run_db_migrations(dsn: str) -> None:
LOGGER.info('Running DB migrations on %r', dsn)
alembic_cfg = Config('alembic.ini')
alembic_cfg.set_main_option('sqlalchemy.url', dsn)
command.upgrade(alembic_cfg, 'head')
@pingzh
Copy link
Author

pingzh commented Feb 10, 2021

Might need to change it, so it wont affect the current logging

--- a/migrations/env.py
+++ b/migrations/env.py
@@ -11,7 +11,7 @@ config = context.config

 # Interpret the config file for Python logging.
 # This line sets up loggers basically.
-fileConfig(config.config_file_name)
+# fileConfig(config.config_file_name)

 # add your model's MetaData object here
 # for 'autogenerate' support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment