##// END OF EJS Templates
svn-proxy: data migration for svn http settings
marcink -
r758:645c556e default
parent child Browse files
Show More
@@ -0,0 +1,85 b''
1 import logging
2
3 from sqlalchemy import *
4
5 from rhodecode.model import init_model_encryption, meta
6 from rhodecode.lib.utils2 import safe_str
7 from rhodecode.lib.dbmigrate.versions import _reset_base, notify
8
9 log = logging.getLogger(__name__)
10
11
12 def get_all_settings(models):
13 settings = {
14 'rhodecode_' + result.app_settings_name: result.app_settings_value
15 for result in models.RhodeCodeSetting.query()
16 }
17 return settings
18
19
20 def get_ui_by_section_and_key(models, section, key):
21 q = models.RhodeCodeUi.query()
22 q = q.filter(models.RhodeCodeUi.ui_section == section)
23 q = q.filter(models.RhodeCodeUi.ui_key == key)
24 return q.scalar()
25
26
27 def create_ui_section_value(models, Session, section, val, key=None, active=True):
28 new_ui = models.RhodeCodeUi()
29 new_ui.ui_section = section
30 new_ui.ui_value = val
31 new_ui.ui_active = active
32 new_ui.ui_key = key
33
34 Session().add(new_ui)
35 return new_ui
36
37
38 def create_or_update_ui(
39 models, Session, section, key, value=None, active=None):
40 ui = get_ui_by_section_and_key(models, section, key)
41 if not ui:
42 active = True if active is None else active
43 create_ui_section_value(
44 models, Session, section, value, key=key, active=active)
45 else:
46 if active is not None:
47 ui.ui_active = active
48 if value is not None:
49 ui.ui_value = value
50 Session().add(ui)
51
52
53 def upgrade(migrate_engine):
54 """
55 Upgrade operations go here.
56 Don't create your own engine; bind migrate_engine to your metadata
57 """
58 _reset_base(migrate_engine)
59 from rhodecode.lib.dbmigrate.schema import db_4_4_0_1
60 init_model_encryption(db_4_4_0_1)
61 fixups(db_4_4_0_1, meta.Session)
62
63
64 def downgrade(migrate_engine):
65 meta = MetaData()
66 meta.bind = migrate_engine
67
68
69 def fixups(models, Session):
70 current_settings = get_all_settings(models)
71
72 svn_proxy_enabled = safe_str(current_settings.get(
73 'rhodecode_proxy_subversion_http_requests', 'False'))
74 svn_proxy_url = current_settings.get(
75 'rhodecode_subversion_http_server_url', '')
76
77 create_or_update_ui(
78 models, Session, 'vcs_svn_proxy', 'http_requests_enabled',
79 value=svn_proxy_enabled)
80
81 create_or_update_ui(
82 models, Session, 'vcs_svn_proxy', 'http_server_url',
83 value=svn_proxy_url)
84
85 Session().commit()
@@ -51,7 +51,7 b' PYRAMID_SETTINGS = {}'
51 51 EXTENSIONS = {}
52 52
53 53 __version__ = ('.'.join((str(each) for each in VERSION[:3])))
54 __dbversion__ = 57 # defines current db version for migrations
54 __dbversion__ = 58 # defines current db version for migrations
55 55 __platform__ = platform.system()
56 56 __license__ = 'AGPLv3, and Commercial License'
57 57 __author__ = 'RhodeCode GmbH'
General Comments 0
You need to be logged in to leave comments. Login now