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 logging.config import fileConfig 
 4   
 5  # this is the Alembic Config object, which provides 
 6  # access to the values within the .ini file in use. 
 7  config = context.config 
 8   
 9  # Interpret the config file for Python logging. 
10  # This line sets up loggers basically. 
11  fileConfig(config.config_file_name) 
12   
13  # add your model's MetaData object here 
14  # for 'autogenerate' support 
15  # from myapp import mymodel 
16  # target_metadata = mymodel.Base.metadata 
17  import sys 
18  import os 
19   
20  # alembic doesn't include cwd by default 
21  sys.path.append(os.getcwd()) 
22   
23  from coprs import db 
24  target_metadata = db.metadata 
25   
26  # other values from the config, defined by the needs of env.py, 
27  # can be acquired: 
28  # my_important_option = config.get_main_option("my_important_option") 
29  # ... etc. 
30   
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
51 -def run_migrations_online():
52 """Run migrations in 'online' mode. 53 54 In this scenario we need to create an Engine 55 and associate a connection with the context. 56 57 """ 58 connection = db.engine.connect() 59 context.configure( 60 connection=connection, 61 target_metadata=target_metadata 62 ) 63 64 try: 65 with context.begin_transaction(): 66 context.run_migrations() 67 finally: 68 connection.close()
69 70 if context.is_offline_mode(): 71 run_migrations_offline() 72 else: 73 run_migrations_online() 74