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.
12 fileConfig(config
.config_file_name
)
14 # add your model's MetaData object here
15 # for 'autogenerate' support
16 # from myapp import mymodel
17 # target_metadata = mymodel.Base.metadata
18 target_metadata
= None
20 # other values from the config, defined by the needs of env.py,
22 # my_important_option = config.get_main_option("my_important_option")
25 def run_migrations_offline():
26 """Run migrations in 'offline' mode.
28 This configures the context with just a URL
29 and not an Engine, though an Engine is acceptable
30 here as well. By skipping the Engine creation
31 we don't even need a DBAPI to be available.
33 Calls to context.execute() here emit the given string to the
37 url
= config
.get_main_option("sqlalchemy.url")
38 context
.configure(url
=url
, target_metadata
=target_metadata
)
40 with context
.begin_transaction():
41 context
.run_migrations()
43 def run_migrations_online():
44 """Run migrations in 'online' mode.
46 In this scenario we need to create an Engine
47 and associate a connection with the context.
50 engine
= engine_from_config(
51 config
.get_section(config
.config_ini_section
),
53 poolclass
=pool
.NullPool
)
55 connection
= engine
.connect()
57 connection
=connection
,
58 target_metadata
=target_metadata
62 with context
.begin_transaction():
63 context
.run_migrations()
67 if context
.is_offline_mode():
68 run_migrations_offline()
70 run_migrations_online()