diff --git a/alembic.ini b/alembic.ini index fc13137..a8cb586 100644 --- a/alembic.ini +++ b/alembic.ini @@ -1,37 +1,10 @@ -# A generic, single database configuration. +# A single database configuration, +# sqlalchemy.url defined in env.py [alembic] # path to migration scripts 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 [loggers] keys = root,sqlalchemy,alembic diff --git a/alembic/env.py b/alembic/env.py index 058378b..2f7c635 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -1,4 +1,6 @@ -from __future__ import with_statement +import os +import importlib + from alembic import context from sqlalchemy import engine_from_config, pool from logging.config import fileConfig @@ -11,16 +13,17 @@ config = context.config # This line sets up loggers basically. 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 # for 'autogenerate' support # from myapp import mymodel # target_metadata = mymodel.Base.metadata 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():