Passed
Pull Request — dev (#82)
by Stephan
01:22
created

env   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 5

2 Functions

Rating   Name   Duplication   Size   Complexity  
A run_migrations_online() 0 20 3
A run_migrations_offline() 0 22 2
1
from logging.config import fileConfig
2
3
from alembic import context
4
from sqlalchemy import engine_from_config, pool
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
26
def run_migrations_offline():
27
    """Run migrations in 'offline' mode.
28
29
    This configures the context with just a URL
30
    and not an Engine, though an Engine is acceptable
31
    here as well.  By skipping the Engine creation
32
    we don't even need a DBAPI to be available.
33
34
    Calls to context.execute() here emit the given string to the
35
    script output.
36
37
    """
38
    url = config.get_main_option("sqlalchemy.url")
39
    context.configure(
40
        url=url,
41
        target_metadata=target_metadata,
42
        literal_binds=True,
43
        dialect_opts={"paramstyle": "named"},
44
    )
45
46
    with context.begin_transaction():
47
        context.run_migrations()
48
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
    connectable = engine_from_config(
58
        config.get_section(config.config_ini_section),
59
        prefix="sqlalchemy.",
60
        poolclass=pool.NullPool,
61
    )
62
63
    with connectable.connect() as connection:
64
        context.configure(
65
            connection=connection, target_metadata=target_metadata
66
        )
67
68
        with context.begin_transaction():
69
            context.run_migrations()
70
71
72
if context.is_offline_mode():
73
    run_migrations_offline()
74
else:
75
    run_migrations_online()
76