Simplify migrations automation

This commit is contained in:
Denis Makogon 2016-11-28 14:56:50 +02:00
parent 7eedd99ee1
commit 1e5a654987
3 changed files with 6 additions and 3 deletions

View File

@ -74,9 +74,9 @@ Migrations
---------- ----------
Once all dependencies are installed it is necessary to run database migrations. Once all dependencies are installed it is necessary to run database migrations.
Before that please edit [alembic.ini](alembic.ini) line #32 Before that it is necessary to set env variable:
sqlalchemy.url = mysql+pymysql://root:root@localhost/functions export LAOS_MIGRATIONS_DB=mysql+pymysql://root:root@localhost/functions
In this section please specify connection URI to your own MySQL database. In this section please specify connection URI to your own MySQL database.
Once the file is saved, just use alembic to apply the migrations: Once the file is saved, just use alembic to apply the migrations:

View File

@ -29,7 +29,7 @@ script_location = migrations
# are written from script.py.mako # are written from script.py.mako
# output_encoding = utf-8 # output_encoding = utf-8
sqlalchemy.url = mysql+pymysql://root:root@192.168.0.112/functions sqlalchemy.url = ""
# Logging configuration # Logging configuration

View File

@ -3,6 +3,8 @@ from alembic import context
from sqlalchemy import engine_from_config, pool from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig from logging.config import fileConfig
import os
# this is the Alembic Config object, which provides # this is the Alembic Config object, which provides
# access to the values within the .ini file in use. # access to the values within the .ini file in use.
config = context.config config = context.config
@ -21,6 +23,7 @@ target_metadata = None
# can be acquired: # can be acquired:
# my_important_option = config.get_main_option("my_important_option") # my_important_option = config.get_main_option("my_important_option")
# ... etc. # ... etc.
config.set_main_option("sqlalchemy.url", os.getenv("LAOS_MIGRATIONS_DB"))
def run_migrations_offline(): def run_migrations_offline():