Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-backend / pithos / backends / lib / sqlalchemy / alembic / env.py @ 5f8bbf54

History | View | Annotate | Download (2 kB)

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
target_metadata = None
19

    
20
# other values from the config, defined by the needs of env.py,
21
# can be acquired:
22
# my_important_option = config.get_main_option("my_important_option")
23
# ... etc.
24

    
25
def run_migrations_offline():
26
    """Run migrations in 'offline' mode.
27

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.
32
    
33
    Calls to context.execute() here emit the given string to the
34
    script output.
35
    
36
    """
37
    url = config.get_main_option("sqlalchemy.url")
38
    context.configure(url=url)
39

    
40
    with context.begin_transaction():
41
        context.run_migrations()
42

    
43
def run_migrations_online():
44
    """Run migrations in 'online' mode.
45

46
    In this scenario we need to create an Engine
47
    and associate a connection with the context.
48
    
49
    """
50
    engine = engine_from_config(
51
                config.get_section(config.config_ini_section), 
52
                prefix='sqlalchemy.', 
53
                poolclass=pool.NullPool)
54

    
55
    connection = engine.connect()
56
    context.configure(
57
                connection=connection, 
58
                target_metadata=target_metadata
59
                )
60

    
61
    try:
62
        with context.begin_transaction():
63
            context.run_migrations()
64
    finally:
65
        connection.close()
66

    
67
if context.is_offline_mode():
68
    run_migrations_offline()
69
else:
70
    run_migrations_online()
71