Module env
[hide private]
[frames] | no frames]

Source Code for Module env

 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 
 5   
 6  # this is the Alembic Config object, which provides 
 7  # access to the values within the .ini file in use. 
 8  config = context.config 
 9   
10  # Interpret the config file for Python logging.  
11  # This line sets up loggers basically. 
12  fileConfig(config.config_file_name) 
13   
14  # add your model's MetaData object here 
15  # for 'autogenerate' support 
16  # from myapp import mymodel 
17  # target_metadata = mymodel.Base.metadata 
18  import sys 
19  import os 
20   
21  # alembic doesn't include cwd by default 
22  sys.path.append(os.getcwd()) 
23   
24  from coprs import db 
25  target_metadata = db.metadata 
26   
27  # other values from the config, defined by the needs of env.py, 
28  # can be acquired: 
29  # my_important_option = config.get_main_option("my_important_option") 
30  # ... etc. 
31   
32 -def run_migrations_offline():
33 """Run migrations in 'offline' mode. 34 35 This configures the context with just a URL 36 and not an Engine, though an Engine is acceptable 37 here as well. By skipping the Engine creation 38 we don't even need a DBAPI to be available. 39 40 Calls to context.execute() here emit the given string to the 41 script output. 42 43 """ 44 url = config.get_main_option("sqlalchemy.url") 45 context.configure(url=url) 46 47 with context.begin_transaction(): 48 context.run_migrations()
49
50 -def run_migrations_online():
51 """Run migrations in 'online' mode. 52 53 In this scenario we need to create an Engine 54 and associate a connection with the context. 55 56 """ 57 connection = db.engine.connect() 58 context.configure( 59 connection=connection, 60 target_metadata=target_metadata 61 ) 62 63 try: 64 with context.begin_transaction(): 65 context.run_migrations() 66 finally: 67 connection.close()
68 69 if context.is_offline_mode(): 70 run_migrations_offline() 71 else: 72 run_migrations_online() 73