62 lines
1.3 KiB
Python
62 lines
1.3 KiB
Python
from __future__ import with_statement
|
|
|
|
import logging
|
|
import os
|
|
from logging.config import fileConfig
|
|
|
|
from flask import current_app
|
|
from alembic import context
|
|
|
|
config = context.config
|
|
|
|
# Safe logging configuration
|
|
if config.config_file_name and os.path.exists(config.config_file_name):
|
|
try:
|
|
fileConfig(config.config_file_name, disable_existing_loggers=False)
|
|
except Exception:
|
|
pass
|
|
|
|
logger = logging.getLogger("alembic.env")
|
|
|
|
from mikromon import db
|
|
from mikromon.models import * # noqa
|
|
|
|
target_metadata = db.metadata
|
|
|
|
|
|
def get_url():
|
|
return current_app.config.get("SQLALCHEMY_DATABASE_URI")
|
|
|
|
|
|
def run_migrations_offline():
|
|
url = get_url()
|
|
|
|
context.configure(
|
|
url=url,
|
|
target_metadata=target_metadata,
|
|
literal_binds=True,
|
|
compare_type=True,
|
|
)
|
|
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
def run_migrations_online():
|
|
connectable = db.engine
|
|
|
|
with connectable.connect() as connection:
|
|
context.configure(
|
|
connection=connection,
|
|
target_metadata=target_metadata,
|
|
compare_type=True,
|
|
)
|
|
|
|
with context.begin_transaction():
|
|
context.run_migrations()
|
|
|
|
|
|
if context.is_offline_mode():
|
|
run_migrations_offline()
|
|
else:
|
|
run_migrations_online() |