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
7
8 config = context.config
9
10
11
12 fileConfig(config.config_file_name)
13
14
15
16
17
18 import sys
19 import os
20
21
22 sys.path.append(os.getcwd())
23
24 from coprs import db
25 target_metadata = db.metadata
26
27
28
29
30
31
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
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