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
6 # this is the Alembic Config object, which provides
7 # access to the values within the .ini file in use.
8 config = context.config
10 # Interpret the config file for Python logging.
11 # This line sets up loggers basically.
13 fileConfig(config.config_file_name)
17 # add your model's MetaData object here
18 # for 'autogenerate' support
19 # from myapp import mymodel
20 # target_metadata = mymodel.Base.metadata
21 target_metadata = None
23 # other values from the config, defined by the needs of env.py,
25 # my_important_option = config.get_main_option("my_important_option")
28 def run_migrations_offline():
29 """Run migrations in 'offline' mode.
31 This configures the context with just a URL
32 and not an Engine, though an Engine is acceptable
33 here as well. By skipping the Engine creation
34 we don't even need a DBAPI to be available.
36 Calls to context.execute() here emit the given string to the
40 url = config.get_main_option("sqlalchemy.url")
41 context.configure(url=url)
43 with context.begin_transaction():
44 context.run_migrations()
46 def run_migrations_online():
47 """Run migrations in 'online' mode.
49 In this scenario we need to create an Engine
50 and associate a connection with the context.
53 engine = engine_from_config(
54 config.get_section(config.config_ini_section),
56 poolclass=pool.NullPool)
58 connection = engine.connect()
60 connection=connection,
61 target_metadata=target_metadata
65 with context.begin_transaction():
66 context.run_migrations()
70 if context.is_offline_mode():
71 run_migrations_offline()
73 run_migrations_online()