1 from __future__ import with_statement
2 from alembic import context
3 from sqlalchemy import engine_from_config, pool
4 from logging.config import fileConfig
8 from synnefo.settings import PITHOS_BACKEND_DB_CONNECTION
12 from synnefo.settings import BACKEND_DB_CONNECTION as \
13 PITHOS_BACKEND_DB_CONNECTION
15 PITHOS_BACKEND_DB_CONNECTION = None
17 # this is the Alembic Config object, which provides
18 # access to the values within the .ini file in use.
19 config = context.config
21 # Interpret the config file for Python logging.
22 # This line sets up loggers basically.
23 fileConfig(config.config_file_name)
25 # add your model's MetaData object here
26 # for 'autogenerate' support
27 # from myapp import mymodel
28 # target_metadata = mymodel.Base.metadata
29 target_metadata = None
31 # other values from the config, defined by the needs of env.py,
33 # my_important_option = config.get_main_option("my_important_option")
36 db = config.get_main_option("sqlalchemy.url", PITHOS_BACKEND_DB_CONNECTION)
37 config.set_main_option("sqlalchemy.url", db)
39 def run_migrations_offline():
40 """Run migrations in 'offline' mode.
42 This configures the context with just a URL
43 and not an Engine, though an Engine is acceptable
44 here as well. By skipping the Engine creation
45 we don't even need a DBAPI to be available.
47 Calls to context.execute() here emit the given string to the
51 url = config.get_main_option("sqlalchemy.url")
52 context.configure(url=url)
54 with context.begin_transaction():
55 context.run_migrations()
57 def run_migrations_online():
58 """Run migrations in 'online' mode.
60 In this scenario we need to create an Engine
61 and associate a connection with the context.
64 engine = engine_from_config(
65 config.get_section(config.config_ini_section),
67 poolclass=pool.NullPool)
69 connection = engine.connect()
71 connection=connection,
72 target_metadata=target_metadata
76 with context.begin_transaction():
77 context.run_migrations()
81 if context.is_offline_mode():
82 run_migrations_offline()
84 run_migrations_online()