Show More
@@ -1,75 +1,78 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2010-2016 RhodeCode GmbH |
|
3 | # Copyright (C) 2010-2016 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # AppEnlight Enterprise Edition, including its added features, Support |
|
18 | # AppEnlight Enterprise Edition, including its added features, Support | |
19 | # services, and proprietary license terms, please see |
|
19 | # services, and proprietary license terms, please see | |
20 | # https://rhodecode.com/licenses/ |
|
20 | # https://rhodecode.com/licenses/ | |
21 |
|
21 | |||
22 | import argparse |
|
22 | import argparse | |
23 | import logging |
|
23 | import logging | |
24 | import sys |
|
24 | import sys | |
25 |
|
25 | |||
26 | from alembic.config import Config |
|
26 | from alembic.config import Config | |
27 | from alembic import command |
|
27 | from alembic import command | |
28 | from pyramid.paster import setup_logging, bootstrap |
|
28 | from pyramid.paster import setup_logging, bootstrap | |
29 | from pyramid.threadlocal import get_current_registry, get_current_request |
|
29 | from pyramid.threadlocal import get_current_registry, get_current_request | |
30 |
|
30 | |||
31 | from appenlight.lib import get_callable |
|
31 | from appenlight.lib import get_callable | |
32 | from appenlight.models.services.config import ConfigService |
|
32 | from appenlight.models.services.config import ConfigService | |
33 |
|
33 | |||
34 | log = logging.getLogger(__name__) |
|
34 | log = logging.getLogger(__name__) | |
35 |
|
35 | |||
36 |
|
36 | |||
37 | def main(argv=sys.argv): |
|
37 | def main(argv=sys.argv): | |
38 | parser = argparse.ArgumentParser( |
|
38 | parser = argparse.ArgumentParser( | |
39 | description='Migrate AppEnlight database to latest version', |
|
39 | description='Migrate AppEnlight database to latest version', | |
40 | add_help=False) |
|
40 | add_help=False) | |
41 | parser.add_argument('-c', '--config', required=True, |
|
41 | parser.add_argument('-c', '--config', required=True, | |
42 | help='Configuration ini file of application') |
|
42 | help='Configuration ini file of application') | |
43 | args = parser.parse_args() |
|
43 | args = parser.parse_args() | |
44 | config_uri = args.config |
|
44 | config_uri = args.config | |
45 |
|
45 | |||
46 | setup_logging(config_uri) |
|
46 | setup_logging(config_uri) | |
47 | bootstrap(config_uri) |
|
47 | bootstrap(config_uri) | |
48 | registry = get_current_registry() |
|
48 | registry = get_current_registry() | |
49 | alembic_cfg = Config() |
|
49 | alembic_cfg = Config() | |
|
50 | alembic_cfg.set_main_option("sqlalchemy.echo", 'true') | |||
50 | alembic_cfg.set_main_option("script_location", |
|
51 | alembic_cfg.set_main_option("script_location", | |
51 | "ziggurat_foundations:migrations") |
|
52 | "ziggurat_foundations:migrations") | |
52 | alembic_cfg.set_main_option("sqlalchemy.url", |
|
53 | alembic_cfg.set_main_option("sqlalchemy.url", | |
53 | registry.settings["sqlalchemy.url"]) |
|
54 | registry.settings["sqlalchemy.url"]) | |
54 | command.upgrade(alembic_cfg, "head") |
|
55 | command.upgrade(alembic_cfg, "head") | |
55 | alembic_cfg = Config() |
|
56 | alembic_cfg = Config() | |
|
57 | alembic_cfg.set_main_option("sqlalchemy.echo", 'true') | |||
56 | alembic_cfg.set_main_option("script_location", "appenlight:migrations") |
|
58 | alembic_cfg.set_main_option("script_location", "appenlight:migrations") | |
57 | alembic_cfg.set_main_option("sqlalchemy.url", |
|
59 | alembic_cfg.set_main_option("sqlalchemy.url", | |
58 | registry.settings["sqlalchemy.url"]) |
|
60 | registry.settings["sqlalchemy.url"]) | |
59 | command.upgrade(alembic_cfg, "head") |
|
61 | command.upgrade(alembic_cfg, "head") | |
60 |
|
62 | |||
61 | for plugin_name, config in registry.appenlight_plugins.items(): |
|
63 | for plugin_name, config in registry.appenlight_plugins.items(): | |
62 | if config['sqlalchemy_migrations']: |
|
64 | if config['sqlalchemy_migrations']: | |
63 | alembic_cfg = Config() |
|
65 | alembic_cfg = Config() | |
64 | alembic_cfg.set_main_option("script_location", |
|
66 | alembic_cfg.set_main_option("script_location", | |
65 | config['sqlalchemy_migrations']) |
|
67 | config['sqlalchemy_migrations']) | |
66 | alembic_cfg.set_main_option("sqlalchemy.url", |
|
68 | alembic_cfg.set_main_option("sqlalchemy.url", | |
67 | registry.settings["sqlalchemy.url"]) |
|
69 | registry.settings["sqlalchemy.url"]) | |
|
70 | alembic_cfg.set_main_option("sqlalchemy.echo", 'true') | |||
68 | command.upgrade(alembic_cfg, "head") |
|
71 | command.upgrade(alembic_cfg, "head") | |
69 |
|
72 | |||
70 | with get_current_request().tm: |
|
73 | with get_current_request().tm: | |
71 | ConfigService.setup_default_values() |
|
74 | ConfigService.setup_default_values() | |
72 |
|
75 | |||
73 | for plugin_name, config in registry.appenlight_plugins.items(): |
|
76 | for plugin_name, config in registry.appenlight_plugins.items(): | |
74 | if config['default_values_setter']: |
|
77 | if config['default_values_setter']: | |
75 | get_callable(config['default_values_setter'])() |
|
78 | get_callable(config['default_values_setter'])() |
General Comments 0
You need to be logged in to leave comments.
Login now