Show More
@@ -0,0 +1,57 | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | ||
|
3 | import logging | |
|
4 | ||
|
5 | from rhodecode.lib.dbmigrate.versions import _reset_base | |
|
6 | from rhodecode.model import init_model_encryption, meta | |
|
7 | ||
|
8 | log = logging.getLogger(__name__) | |
|
9 | ||
|
10 | ||
|
11 | def upgrade(migrate_engine): | |
|
12 | """ | |
|
13 | Upgrade operations go here. | |
|
14 | Don't create your own engine; bind migrate_engine to your metadata | |
|
15 | """ | |
|
16 | _reset_base(migrate_engine) | |
|
17 | from rhodecode.lib.dbmigrate.schema import db_3_7_0_0 | |
|
18 | init_model_encryption(db_3_7_0_0) | |
|
19 | fixups(db_3_7_0_0, meta.Session) | |
|
20 | ||
|
21 | ||
|
22 | def downgrade(migrate_engine): | |
|
23 | pass | |
|
24 | ||
|
25 | ||
|
26 | AUTH_PLUGINS_SETTING = "auth_plugins" | |
|
27 | ||
|
28 | PLUGIN_RENAME_MAP = { | |
|
29 | 'egg:rhodecode-enterprise-ee#token': 'egg:rhodecode-enterprise-ce#token', | |
|
30 | } | |
|
31 | ||
|
32 | ||
|
33 | def rename_plugins(models, Session): | |
|
34 | query = models.RhodeCodeSetting.query().filter( | |
|
35 | models.RhodeCodeSetting.app_settings_name == AUTH_PLUGINS_SETTING) | |
|
36 | plugin_setting = query.scalar() | |
|
37 | plugins = plugin_setting.app_settings_value | |
|
38 | ||
|
39 | new_plugins = [] | |
|
40 | ||
|
41 | for plugin_id in plugins: | |
|
42 | new_plugin_id = PLUGIN_RENAME_MAP.get(plugin_id, None) | |
|
43 | if new_plugin_id: | |
|
44 | new_plugins.append(new_plugin_id) | |
|
45 | else: | |
|
46 | new_plugins.append(plugin_id) | |
|
47 | ||
|
48 | plugin_setting.app_settings_value = ','.join(new_plugins) | |
|
49 | ||
|
50 | log.info("Rename of auth plugin IDs") | |
|
51 | log.info("Original setting value: %s", plugins) | |
|
52 | log.info("New setting value: %s", new_plugins) | |
|
53 | ||
|
54 | ||
|
55 | def fixups(models, Session): | |
|
56 | rename_plugins(models, Session) | |
|
57 | Session().commit() |
General Comments 0
You need to be logged in to leave comments.
Login now