|
|
# -*- coding: utf-8 -*-
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
# (at your option) any later version.
|
|
|
#
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
# GNU General Public License for more details.
|
|
|
#
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
# Alembic migration environment (configuration).
|
|
|
|
|
|
from logging.config import fileConfig
|
|
|
|
|
|
from alembic import context
|
|
|
from sqlalchemy import engine_from_config, pool
|
|
|
|
|
|
|
|
|
# The alembic.config.Config object, which wraps the current .ini file.
|
|
|
config = context.config
|
|
|
|
|
|
# Interpret the config file for Python logging.
|
|
|
# This line sets up loggers basically.
|
|
|
fileConfig(config.config_file_name)
|
|
|
|
|
|
|
|
|
def run_migrations_offline():
|
|
|
"""Run migrations in 'offline' (--sql) mode.
|
|
|
|
|
|
This produces an SQL script instead of directly applying the changes.
|
|
|
Some migrations may not run in offline mode.
|
|
|
"""
|
|
|
url = config.get_main_option("sqlalchemy.url")
|
|
|
context.configure(
|
|
|
url=url,
|
|
|
literal_binds=True,
|
|
|
)
|
|
|
|
|
|
with context.begin_transaction():
|
|
|
context.run_migrations()
|
|
|
|
|
|
|
|
|
def run_migrations_online():
|
|
|
"""Run migrations in 'online' mode.
|
|
|
|
|
|
Connects to the database and directly applies the necessary
|
|
|
migrations.
|
|
|
"""
|
|
|
connectable = engine_from_config(
|
|
|
config.get_section(config.config_ini_section),
|
|
|
prefix='sqlalchemy.',
|
|
|
poolclass=pool.NullPool)
|
|
|
|
|
|
with connectable.connect() as connection:
|
|
|
context.configure(
|
|
|
connection=connection,
|
|
|
)
|
|
|
|
|
|
with context.begin_transaction():
|
|
|
context.run_migrations()
|
|
|
|
|
|
|
|
|
if context.is_offline_mode():
|
|
|
run_migrations_offline()
|
|
|
else:
|
|
|
run_migrations_online()
|
|
|
|