alembic: Load configuration from ogn config

If environment variable OGN_CONFIG_MODULE is defined,
load configuration from this python module, otherwise load "config.default".
pull/37/head
Fabian P. Schmidt 2016-01-31 02:20:00 +01:00
rodzic 7727f0c606
commit 6511d6da38
2 zmienionych plików z 10 dodań i 34 usunięć

Wyświetl plik

@ -1,37 +1,10 @@
# A generic, single database configuration. # A single database configuration,
# sqlalchemy.url defined in env.py
[alembic] [alembic]
# path to migration scripts # path to migration scripts
script_location = alembic script_location = alembic
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
# max length of characters to apply to the
# "slug" field
#truncate_slug_length = 40
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false
# version location specification; this defaults
# to alembic/versions. When using multiple version
# directories, initial revisions must be specified with --version-path
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8
sqlalchemy.url = sqlite:///beacons.db
# Logging configuration # Logging configuration
[loggers] [loggers]
keys = root,sqlalchemy,alembic keys = root,sqlalchemy,alembic

Wyświetl plik

@ -1,4 +1,6 @@
from __future__ import with_statement import os
import importlib
from alembic import context 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
@ -11,16 +13,17 @@ config = context.config
# This line sets up loggers basically. # This line sets up loggers basically.
fileConfig(config.config_file_name) fileConfig(config.config_file_name)
# Get database path from ogn config
os.environ.setdefault('OGN_CONFIG_MODULE', 'config.default')
ogn_config = importlib.import_module(os.environ['OGN_CONFIG_MODULE'])
alembic_config.set_main_option('sqlalchemy.url', ogn_config.SQLALCHEMY_DATABASE_URI)
# add your model's MetaData object here # add your model's MetaData object here
# for 'autogenerate' support # for 'autogenerate' support
# from myapp import mymodel # from myapp import mymodel
# target_metadata = mymodel.Base.metadata # target_metadata = mymodel.Base.metadata
target_metadata = None target_metadata = None
# 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_offline(): def run_migrations_offline():