Show More
@@ -1,43 +1,44 b'' | |||||
1 | from __future__ import with_statement |
|
1 | # -*- coding: utf-8 -*- | |
|
2 | # This program is free software: you can redistribute it and/or modify | |||
|
3 | # it under the terms of the GNU General Public License as published by | |||
|
4 | # the Free Software Foundation, either version 3 of the License, or | |||
|
5 | # (at your option) any later version. | |||
|
6 | # | |||
|
7 | # This program is distributed in the hope that it will be useful, | |||
|
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
10 | # GNU General Public License for more details. | |||
|
11 | # | |||
|
12 | # You should have received a copy of the GNU General Public License | |||
|
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
|
14 | ||||
|
15 | # Alembic migration environment (configuration). | |||
|
16 | ||||
|
17 | from logging.config import fileConfig | |||
|
18 | ||||
2 | from alembic import context |
|
19 | from alembic import context | |
3 | from sqlalchemy import engine_from_config, pool |
|
20 | from sqlalchemy import engine_from_config, pool | |
4 | from logging.config import fileConfig |
|
21 | ||
5 |
|
22 | |||
6 | # this is the Alembic Config object, which provides |
|
23 | # The alembic.config.Config object, which wraps the current .ini file. | |
7 | # access to the values within the .ini file in use. |
|
|||
8 | config = context.config |
|
24 | config = context.config | |
9 |
|
25 | |||
10 | # Interpret the config file for Python logging. |
|
26 | # Interpret the config file for Python logging. | |
11 | # This line sets up loggers basically. |
|
27 | # This line sets up loggers basically. | |
12 | fileConfig(config.config_file_name) |
|
28 | fileConfig(config.config_file_name) | |
13 |
|
29 | |||
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 |
|
30 | |||
26 | def run_migrations_offline(): |
|
31 | def run_migrations_offline(): | |
27 | """Run migrations in 'offline' mode. |
|
32 | """Run migrations in 'offline' (--sql) mode. | |
28 |
|
33 | |||
29 | This configures the context with just a URL |
|
34 | This produces an SQL script instead of directly applying the changes. | |
30 | and not an Engine, though an Engine is acceptable |
|
35 | Some migrations may not run in offline mode. | |
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 | """ |
|
36 | """ | |
38 | url = config.get_main_option("sqlalchemy.url") |
|
37 | url = config.get_main_option("sqlalchemy.url") | |
39 | context.configure( |
|
38 | context.configure( | |
40 | url=url, target_metadata=target_metadata, literal_binds=True) |
|
39 | url=url, | |
|
40 | literal_binds=True, | |||
|
41 | ) | |||
41 |
|
42 | |||
42 | with context.begin_transaction(): |
|
43 | with context.begin_transaction(): | |
43 | context.run_migrations() |
|
44 | context.run_migrations() | |
@@ -46,9 +47,8 b' def run_migrations_offline():' | |||||
46 | def run_migrations_online(): |
|
47 | def run_migrations_online(): | |
47 | """Run migrations in 'online' mode. |
|
48 | """Run migrations in 'online' mode. | |
48 |
|
49 | |||
49 | In this scenario we need to create an Engine |
|
50 | Connects to the database and directly applies the necessary | |
50 | and associate a connection with the context. |
|
51 | migrations. | |
51 |
|
||||
52 | """ |
|
52 | """ | |
53 | connectable = engine_from_config( |
|
53 | connectable = engine_from_config( | |
54 | config.get_section(config.config_ini_section), |
|
54 | config.get_section(config.config_ini_section), | |
@@ -58,12 +58,12 b' def run_migrations_online():' | |||||
58 | with connectable.connect() as connection: |
|
58 | with connectable.connect() as connection: | |
59 | context.configure( |
|
59 | context.configure( | |
60 | connection=connection, |
|
60 | connection=connection, | |
61 | target_metadata=target_metadata |
|
|||
62 | ) |
|
61 | ) | |
63 |
|
62 | |||
64 | with context.begin_transaction(): |
|
63 | with context.begin_transaction(): | |
65 | context.run_migrations() |
|
64 | context.run_migrations() | |
66 |
|
65 | |||
|
66 | ||||
67 | if context.is_offline_mode(): |
|
67 | if context.is_offline_mode(): | |
68 | run_migrations_offline() |
|
68 | run_migrations_offline() | |
69 | else: |
|
69 | else: |
@@ -1,3 +1,18 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | # This program is free software: you can redistribute it and/or modify | |||
|
3 | # it under the terms of the GNU General Public License as published by | |||
|
4 | # the Free Software Foundation, either version 3 of the License, or | |||
|
5 | # (at your option) any later version. | |||
|
6 | # | |||
|
7 | # This program is distributed in the hope that it will be useful, | |||
|
8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
|
9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
|
10 | # GNU General Public License for more details. | |||
|
11 | # | |||
|
12 | # You should have received a copy of the GNU General Public License | |||
|
13 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
|
14 | ||||
|
15 | ## Template for creating new Alembic migration scripts. | |||
1 | """${message} |
|
16 | """${message} | |
2 |
|
17 | |||
3 | Revision ID: ${up_revision} |
|
18 | Revision ID: ${up_revision} | |
@@ -6,7 +21,8 b' Create Date: ${create_date}' | |||||
6 |
|
21 | |||
7 | """ |
|
22 | """ | |
8 |
|
23 | |||
9 | # revision identifiers, used by Alembic. |
|
24 | # The following opaque hexadecimal identifiers ("revisions") are used | |
|
25 | # by Alembic to track this migration script and its relations to others. | |||
10 | revision = ${repr(up_revision)} |
|
26 | revision = ${repr(up_revision)} | |
11 | down_revision = ${repr(down_revision)} |
|
27 | down_revision = ${repr(down_revision)} | |
12 | branch_labels = ${repr(branch_labels)} |
|
28 | branch_labels = ${repr(branch_labels)} |
General Comments 0
You need to be logged in to leave comments.
Login now