|
1 | 1 | import logging |
2 | | -import os |
3 | 2 | from logging.config import fileConfig |
4 | 3 |
|
5 | 4 | from alembic import context |
6 | 5 | from flask import current_app |
7 | 6 | from sqlalchemy import engine_from_config, pool |
8 | 7 |
|
9 | | -from OpenOversight.app import create_app, db |
10 | | -from OpenOversight.app.utils.constants import KEY_DATABASE_URI, KEY_ENV, KEY_ENV_DEV |
| 8 | +from OpenOversight.app.utils.constants import KEY_DATABASE_URI |
11 | 9 |
|
12 | 10 |
|
13 | | -app = create_app(os.environ.get(KEY_ENV, KEY_ENV_DEV)) |
14 | 11 | # this is the Alembic Config object, which provides |
15 | 12 | # access to the values within the .ini file in use. |
16 | 13 | config = context.config |
|
19 | 16 | logger = logging.getLogger("alembic.env") |
20 | 17 |
|
21 | 18 |
|
| 19 | +config.set_main_option("sqlalchemy.url", current_app.config.get(KEY_DATABASE_URI)) |
| 20 | +target_metadata = current_app.extensions["migrate"].db.metadata |
| 21 | + |
| 22 | + |
22 | 23 | def run_migrations_offline(): |
23 | 24 | """Run migrations in 'offline' mode. |
24 | 25 |
|
@@ -77,14 +78,7 @@ def process_revision_directives(context, revision, directives): |
77 | 78 | connection.close() |
78 | 79 |
|
79 | 80 |
|
80 | | -with app.app_context(): |
81 | | - config.set_main_option("sqlalchemy.url", current_app.config.get(KEY_DATABASE_URI)) |
82 | | - target_metadata = current_app.extensions["migrate"].db.metadata |
83 | | - |
84 | | - db.app = app |
85 | | - db.create_all() |
86 | | - |
87 | | - if context.is_offline_mode(): |
88 | | - run_migrations_offline() |
89 | | - else: |
90 | | - run_migrations_online() |
| 81 | +if context.is_offline_mode(): |
| 82 | + run_migrations_offline() |
| 83 | +else: |
| 84 | + run_migrations_online() |
0 commit comments