2016-03-19 20:37:04 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import alembic
|
2017-02-04 00:08:12 +00:00
|
|
|
import sqlalchemy as sa
|
2016-03-19 20:37:04 +00:00
|
|
|
import logging.config
|
|
|
|
|
|
|
|
# make szurubooru module importable
|
|
|
|
dir_to_self = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
sys.path.append(os.path.join(dir_to_self, *[os.pardir] * 2))
|
|
|
|
|
2017-02-05 22:29:21 +00:00
|
|
|
import szurubooru.model.base
|
2016-03-19 20:37:04 +00:00
|
|
|
import szurubooru.config
|
|
|
|
|
|
|
|
alembic_config = alembic.context.config
|
|
|
|
logging.config.fileConfig(alembic_config.config_file_name)
|
|
|
|
|
2016-04-03 20:03:58 +00:00
|
|
|
szuru_config = szurubooru.config.config
|
2016-08-15 17:55:03 +00:00
|
|
|
alembic_config.set_main_option('sqlalchemy.url', szuru_config['database'])
|
2016-03-19 20:37:04 +00:00
|
|
|
|
2017-02-05 22:29:21 +00:00
|
|
|
target_metadata = szurubooru.model.Base.metadata
|
2016-03-19 20:37:04 +00:00
|
|
|
|
2016-08-14 12:22:53 +00:00
|
|
|
|
2016-03-19 20:37:04 +00:00
|
|
|
def run_migrations_offline():
|
|
|
|
'''
|
|
|
|
Run migrations in 'offline' mode.
|
|
|
|
|
|
|
|
This configures the context with just a URL
|
|
|
|
and not an Engine, though an Engine is acceptable
|
|
|
|
here as well. By skipping the Engine creation
|
|
|
|
we don't even need a DBAPI to be available.
|
|
|
|
|
|
|
|
Calls to context.execute() here emit the given string to the
|
|
|
|
script output.
|
|
|
|
'''
|
|
|
|
url = alembic_config.get_main_option('sqlalchemy.url')
|
|
|
|
alembic.context.configure(
|
|
|
|
url=url, target_metadata=target_metadata, literal_binds=True)
|
|
|
|
|
|
|
|
with alembic.context.begin_transaction():
|
|
|
|
alembic.context.run_migrations()
|
|
|
|
|
|
|
|
|
|
|
|
def run_migrations_online():
|
|
|
|
'''
|
|
|
|
Run migrations in 'online' mode.
|
|
|
|
|
|
|
|
In this scenario we need to create an Engine
|
|
|
|
and associate a connection with the context.
|
|
|
|
'''
|
2017-02-04 00:08:12 +00:00
|
|
|
connectable = sa.engine_from_config(
|
2016-03-19 20:37:04 +00:00
|
|
|
alembic_config.get_section(alembic_config.config_ini_section),
|
|
|
|
prefix='sqlalchemy.',
|
2017-02-05 22:29:21 +00:00
|
|
|
poolclass=sa.pool.NullPool)
|
2016-03-19 20:37:04 +00:00
|
|
|
|
|
|
|
with connectable.connect() as connection:
|
|
|
|
alembic.context.configure(
|
|
|
|
connection=connection,
|
|
|
|
target_metadata=target_metadata)
|
|
|
|
|
|
|
|
with alembic.context.begin_transaction():
|
|
|
|
alembic.context.run_migrations()
|
|
|
|
|
2017-01-03 20:35:08 +00:00
|
|
|
|
2016-03-19 20:37:04 +00:00
|
|
|
if alembic.context.is_offline_mode():
|
|
|
|
run_migrations_offline()
|
|
|
|
else:
|
|
|
|
run_migrations_online()
|