# HG changeset patch # User Marcin Kuzminski # Date 2016-09-06 17:16:13 # Node ID 645c556e60497325d08af3a4c141f04ecd45d4f8 # Parent a5f278c1f8304a4ed901bfebb2e43b5ffdfbea56 svn-proxy: data migration for svn http settings diff --git a/rhodecode/__init__.py b/rhodecode/__init__.py --- a/rhodecode/__init__.py +++ b/rhodecode/__init__.py @@ -51,7 +51,7 @@ PYRAMID_SETTINGS = {} EXTENSIONS = {} __version__ = ('.'.join((str(each) for each in VERSION[:3]))) -__dbversion__ = 57 # defines current db version for migrations +__dbversion__ = 58 # defines current db version for migrations __platform__ = platform.system() __license__ = 'AGPLv3, and Commercial License' __author__ = 'RhodeCode GmbH' diff --git a/rhodecode/lib/dbmigrate/versions/058_version_4_4_0.py b/rhodecode/lib/dbmigrate/versions/058_version_4_4_0.py new file mode 100644 --- /dev/null +++ b/rhodecode/lib/dbmigrate/versions/058_version_4_4_0.py @@ -0,0 +1,85 @@ +import logging + +from sqlalchemy import * + +from rhodecode.model import init_model_encryption, meta +from rhodecode.lib.utils2 import safe_str +from rhodecode.lib.dbmigrate.versions import _reset_base, notify + +log = logging.getLogger(__name__) + + +def get_all_settings(models): + settings = { + 'rhodecode_' + result.app_settings_name: result.app_settings_value + for result in models.RhodeCodeSetting.query() + } + return settings + + +def get_ui_by_section_and_key(models, section, key): + q = models.RhodeCodeUi.query() + q = q.filter(models.RhodeCodeUi.ui_section == section) + q = q.filter(models.RhodeCodeUi.ui_key == key) + return q.scalar() + + +def create_ui_section_value(models, Session, section, val, key=None, active=True): + new_ui = models.RhodeCodeUi() + new_ui.ui_section = section + new_ui.ui_value = val + new_ui.ui_active = active + new_ui.ui_key = key + + Session().add(new_ui) + return new_ui + + +def create_or_update_ui( + models, Session, section, key, value=None, active=None): + ui = get_ui_by_section_and_key(models, section, key) + if not ui: + active = True if active is None else active + create_ui_section_value( + models, Session, section, value, key=key, active=active) + else: + if active is not None: + ui.ui_active = active + if value is not None: + ui.ui_value = value + Session().add(ui) + + +def upgrade(migrate_engine): + """ + Upgrade operations go here. + Don't create your own engine; bind migrate_engine to your metadata + """ + _reset_base(migrate_engine) + from rhodecode.lib.dbmigrate.schema import db_4_4_0_1 + init_model_encryption(db_4_4_0_1) + fixups(db_4_4_0_1, meta.Session) + + +def downgrade(migrate_engine): + meta = MetaData() + meta.bind = migrate_engine + + +def fixups(models, Session): + current_settings = get_all_settings(models) + + svn_proxy_enabled = safe_str(current_settings.get( + 'rhodecode_proxy_subversion_http_requests', 'False')) + svn_proxy_url = current_settings.get( + 'rhodecode_subversion_http_server_url', '') + + create_or_update_ui( + models, Session, 'vcs_svn_proxy', 'http_requests_enabled', + value=svn_proxy_enabled) + + create_or_update_ui( + models, Session, 'vcs_svn_proxy', 'http_server_url', + value=svn_proxy_url) + + Session().commit()