1 from __future__ import with_statement
2 from alembic import context
3 from logging.config import fileConfig
4
5
6
7 config = context.config
8
9
10
11 fileConfig(config.config_file_name)
12
13
14
15
16
17 import sys
18 import os
19
20
21 sys.path.append(os.getcwd())
22
23 from coprs import db
24 target_metadata = db.metadata
25
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
50
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