Show More
@@ -0,0 +1,80 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | ||||
|
3 | import logging | |||
|
4 | ||||
|
5 | from sqlalchemy.orm.attributes import flag_modified | |||
|
6 | ||||
|
7 | from rhodecode.lib.dbmigrate.versions import _reset_base | |||
|
8 | from rhodecode.model import init_model_encryption, meta | |||
|
9 | ||||
|
10 | log = logging.getLogger(__name__) | |||
|
11 | ||||
|
12 | ||||
|
13 | def upgrade(migrate_engine): | |||
|
14 | """ | |||
|
15 | Upgrade operations go here. | |||
|
16 | Don't create your own engine; bind migrate_engine to your metadata | |||
|
17 | """ | |||
|
18 | _reset_base(migrate_engine) | |||
|
19 | from rhodecode.lib.dbmigrate.schema import db_3_7_0_0 | |||
|
20 | init_model_encryption(db_3_7_0_0) | |||
|
21 | fixups(db_3_7_0_0, meta.Session) | |||
|
22 | ||||
|
23 | ||||
|
24 | def downgrade(migrate_engine): | |||
|
25 | pass | |||
|
26 | ||||
|
27 | ||||
|
28 | AUTH_PLUGINS_SETTING = "auth_plugins" | |||
|
29 | ||||
|
30 | PLUGIN_RENAME_MAP = { | |||
|
31 | 'egg:rhodecode-enterprise-ce#container': 'egg:rhodecode-enterprise-ce#headers', | |||
|
32 | } | |||
|
33 | ||||
|
34 | SETTINGS_RENAME_MAP = { | |||
|
35 | 'auth_container_cache_ttl': 'auth_headers_cache_ttl', | |||
|
36 | 'auth_container_clean_username': 'auth_headers_clean_username', | |||
|
37 | 'auth_container_enabled': 'auth_headers_enabled', | |||
|
38 | 'auth_container_fallback_header': 'auth_headers_fallback_header', | |||
|
39 | 'auth_container_header': 'auth_headers_header', | |||
|
40 | } | |||
|
41 | ||||
|
42 | ||||
|
43 | def rename_plugins(models, Session): | |||
|
44 | query = models.RhodeCodeSetting.query().filter( | |||
|
45 | models.RhodeCodeSetting.app_settings_name == AUTH_PLUGINS_SETTING) | |||
|
46 | plugin_setting = query.scalar() | |||
|
47 | plugins = plugin_setting.app_settings_value | |||
|
48 | ||||
|
49 | new_plugins = [] | |||
|
50 | ||||
|
51 | for plugin_id in plugins: | |||
|
52 | new_plugin_id = PLUGIN_RENAME_MAP.get(plugin_id, None) | |||
|
53 | if new_plugin_id: | |||
|
54 | new_plugins.append(new_plugin_id) | |||
|
55 | else: | |||
|
56 | new_plugins.append(plugin_id) | |||
|
57 | ||||
|
58 | plugin_setting.app_settings_value = ','.join(new_plugins) | |||
|
59 | ||||
|
60 | log.info("Rename of auth plugin IDs") | |||
|
61 | log.info("Original setting value: %s", plugins) | |||
|
62 | log.info("New setting value: %s", new_plugins) | |||
|
63 | ||||
|
64 | ||||
|
65 | def rename_plugin_settings(models, Session): | |||
|
66 | for old_name, new_name in SETTINGS_RENAME_MAP.items(): | |||
|
67 | query = models.RhodeCodeSetting.query().filter( | |||
|
68 | models.RhodeCodeSetting.app_settings_name == old_name) | |||
|
69 | setting = query.scalar() | |||
|
70 | if setting: | |||
|
71 | setting.app_settings_name = new_name | |||
|
72 | log.info( | |||
|
73 | 'Rename of plugin setting "%s" to "%s"', old_name, new_name) | |||
|
74 | ||||
|
75 | ||||
|
76 | def fixups(models, Session): | |||
|
77 | rename_plugins(models, Session) | |||
|
78 | rename_plugin_settings(models, Session) | |||
|
79 | ||||
|
80 | Session().commit() |
@@ -47,7 +47,7 b' CONFIG = {}' | |||||
47 | EXTENSIONS = {} |
|
47 | EXTENSIONS = {} | |
48 |
|
48 | |||
49 | __version__ = ('.'.join((str(each) for each in VERSION[:3]))) |
|
49 | __version__ = ('.'.join((str(each) for each in VERSION[:3]))) | |
50 |
__dbversion__ = 5 |
|
50 | __dbversion__ = 52 # defines current db version for migrations | |
51 | __platform__ = platform.system() |
|
51 | __platform__ = platform.system() | |
52 | __license__ = 'AGPLv3, and Commercial License' |
|
52 | __license__ = 'AGPLv3, and Commercial License' | |
53 | __author__ = 'RhodeCode GmbH' |
|
53 | __author__ = 'RhodeCode GmbH' |
General Comments 0
You need to be logged in to leave comments.
Login now