# HG changeset patch # User Bradley M. Kuhn # Date 2014-05-23 23:36:09 # Node ID 24498ba2fbecf90061b93684a6366e3b6533149b # Parent f373f182b75606df41773145bcb37d17be0a5425 SETTINGS_PREFIX for identifiers (e.g., db table names) incl. project's name. kallithea.SETTINGS_PREFIX is a variable string used as a prefix for specific external identifiers, such as database table names (and likely later form fields), so that the name of the project need not necessarily be encoded into data. This setting is configurable so that compatibility with old, similar databases can be maintained at the users' request. diff --git a/kallithea/__init__.py b/kallithea/__init__.py --- a/kallithea/__init__.py +++ b/kallithea/__init__.py @@ -22,7 +22,7 @@ This file was forked by the Kallithea pr Original author and date, and relevant copyright and licensing information is below: :created_on: Apr 9, 2010 :author: marcink -:copyright: (c) 2013 RhodeCode GmbH, and others. +:copyright: (c) 2013 RhodeCode GmbH, (C) 2014 Bradley M. Kuhn, and others. :license: GPLv3, see LICENSE.md for more details. """ @@ -44,6 +44,20 @@ CONFIG = {} # Linked module for extensions EXTENSIONS = {} +# SETTINGS_PREFIX is the prefix to use for form fields and database table names. + +# Ideally, SETTINGS_PREFIX would be in an ini file of some sort instead of +# in this code. However, since this is used in kallithea/model/db.py as +# part of the database initialization in code that typically runs before +# CONFIG (above) is populated with settings from the ini file, it's instead +# hard-coded herein. + +SETTINGS_PREFIX = "kallithea_" +# NOTE: If you want compatibility with a database that was originally created +# for use with the Rhodecode software product, changing SETTINGS_PREFIX to +# "rhodecode_" might work to make the old database and forms compatible with +# this application. + try: from kallithea.lib import get_current_revision _rev = get_current_revision(quiet=True) diff --git a/kallithea/lib/dbmigrate/schema/db_1_2_0.py b/kallithea/lib/dbmigrate/schema/db_1_2_0.py --- a/kallithea/lib/dbmigrate/schema/db_1_2_0.py +++ b/kallithea/lib/dbmigrate/schema/db_1_2_0.py @@ -49,6 +49,7 @@ from kallithea.lib.compat import json from kallithea.model.meta import Base, Session from kallithea.lib.caching_query import FromCache +from kallithea import SETTINGS_PREFIX log = logging.getLogger(__name__) @@ -142,7 +143,7 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = (UniqueConstraint('app_settings_name'), {'extend_existing':True}) app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) app_settings_name = Column("app_settings_name", String(length=255, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) @@ -213,7 +214,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = (UniqueConstraint('ui_key'), {'extend_existing':True}) HOOK_UPDATE = 'changegroup.update' diff --git a/kallithea/lib/dbmigrate/schema/db_1_3_0.py b/kallithea/lib/dbmigrate/schema/db_1_3_0.py --- a/kallithea/lib/dbmigrate/schema/db_1_3_0.py +++ b/kallithea/lib/dbmigrate/schema/db_1_3_0.py @@ -51,6 +51,7 @@ from kallithea.lib.caching_query import from kallithea.model.meta import Base, Session import hashlib +from kallithea import SETTINGS_PREFIX log = logging.getLogger(__name__) @@ -157,7 +158,7 @@ class BaseModel(object): return '' % (self.__class__.__name__) class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine':'InnoDB', @@ -232,7 +233,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine':'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_1_4_0.py b/kallithea/lib/dbmigrate/schema/db_1_4_0.py --- a/kallithea/lib/dbmigrate/schema/db_1_4_0.py +++ b/kallithea/lib/dbmigrate/schema/db_1_4_0.py @@ -55,6 +55,8 @@ from kallithea.lib.caching_query import from kallithea.model.meta import Base, Session +from kallithea import SETTINGS_PREFIX + URL_SEP = '/' log = logging.getLogger(__name__) @@ -148,7 +150,7 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -230,7 +232,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_1_5_0.py b/kallithea/lib/dbmigrate/schema/db_1_5_0.py --- a/kallithea/lib/dbmigrate/schema/db_1_5_0.py +++ b/kallithea/lib/dbmigrate/schema/db_1_5_0.py @@ -54,6 +54,8 @@ from kallithea.lib.caching_query import from kallithea.model.meta import Base, Session +from kallithea import SETTINGS_PREFIX + URL_SEP = '/' log = logging.getLogger(__name__) @@ -147,7 +149,7 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -246,7 +248,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_1_5_2.py b/kallithea/lib/dbmigrate/schema/db_1_5_2.py --- a/kallithea/lib/dbmigrate/schema/db_1_5_2.py +++ b/kallithea/lib/dbmigrate/schema/db_1_5_2.py @@ -58,6 +58,8 @@ from kallithea.model.meta import Base, S URL_SEP = '/' log = logging.getLogger(__name__) +from kallithea import SETTINGS_PREFIX + #============================================================================== # BASE CLASSES #============================================================================== @@ -148,7 +150,7 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -247,7 +249,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_1_6_0.py b/kallithea/lib/dbmigrate/schema/db_1_6_0.py --- a/kallithea/lib/dbmigrate/schema/db_1_6_0.py +++ b/kallithea/lib/dbmigrate/schema/db_1_6_0.py @@ -58,6 +58,8 @@ from kallithea.model.meta import Base, S URL_SEP = '/' log = logging.getLogger(__name__) +from kallithea import SETTINGS_PREFIX + #============================================================================== # BASE CLASSES #============================================================================== @@ -148,7 +150,7 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -247,7 +249,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_1_7_0.py b/kallithea/lib/dbmigrate/schema/db_1_7_0.py --- a/kallithea/lib/dbmigrate/schema/db_1_7_0.py +++ b/kallithea/lib/dbmigrate/schema/db_1_7_0.py @@ -58,6 +58,8 @@ from kallithea.model.meta import Base, S URL_SEP = '/' log = logging.getLogger(__name__) +from kallithea import SETTINGS_PREFIX + #============================================================================== # BASE CLASSES #============================================================================== @@ -153,7 +155,7 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -252,7 +254,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_1_8_0.py b/kallithea/lib/dbmigrate/schema/db_1_8_0.py --- a/kallithea/lib/dbmigrate/schema/db_1_8_0.py +++ b/kallithea/lib/dbmigrate/schema/db_1_8_0.py @@ -58,6 +58,8 @@ from kallithea.model.meta import Base, S URL_SEP = '/' log = logging.getLogger(__name__) +from kallithea import SETTINGS_PREFIX + #============================================================================== # BASE CLASSES #============================================================================== @@ -153,7 +155,7 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -270,7 +272,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_2_0_0.py b/kallithea/lib/dbmigrate/schema/db_2_0_0.py --- a/kallithea/lib/dbmigrate/schema/db_2_0_0.py +++ b/kallithea/lib/dbmigrate/schema/db_2_0_0.py @@ -59,6 +59,8 @@ from kallithea.model.meta import Base, S URL_SEP = '/' log = logging.getLogger(__name__) +from kallithea import SETTINGS_PREFIX + #============================================================================== # BASE CLASSES #============================================================================== @@ -161,7 +163,7 @@ class Setting(Base, BaseModel): 'bool': str2bool, 'list': functools.partial(aslist, sep=',') } - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -317,7 +319,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_2_0_1.py b/kallithea/lib/dbmigrate/schema/db_2_0_1.py --- a/kallithea/lib/dbmigrate/schema/db_2_0_1.py +++ b/kallithea/lib/dbmigrate/schema/db_2_0_1.py @@ -56,6 +56,8 @@ from kallithea.lib.caching_query import from kallithea.model.meta import Base, Session +from kallithea import SETTINGS_PREFIX + URL_SEP = '/' log = logging.getLogger(__name__) @@ -164,7 +166,7 @@ class Setting(Base, BaseModel): 'bool': str2bool, 'list': functools.partial(aslist, sep=',') } - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -320,7 +322,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_2_0_2.py b/kallithea/lib/dbmigrate/schema/db_2_0_2.py --- a/kallithea/lib/dbmigrate/schema/db_2_0_2.py +++ b/kallithea/lib/dbmigrate/schema/db_2_0_2.py @@ -59,6 +59,8 @@ from kallithea.model.meta import Base, S URL_SEP = '/' log = logging.getLogger(__name__) +from kallithea import SETTINGS_PREFIX + #============================================================================== # BASE CLASSES #============================================================================== @@ -164,7 +166,7 @@ class Setting(Base, BaseModel): 'bool': str2bool, 'list': functools.partial(aslist, sep=',') } - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -320,7 +322,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_2_1_0.py b/kallithea/lib/dbmigrate/schema/db_2_1_0.py --- a/kallithea/lib/dbmigrate/schema/db_2_1_0.py +++ b/kallithea/lib/dbmigrate/schema/db_2_1_0.py @@ -59,6 +59,8 @@ from kallithea.model.meta import Base, S URL_SEP = '/' log = logging.getLogger(__name__) +from kallithea import SETTINGS_PREFIX + #============================================================================== # BASE CLASSES #============================================================================== @@ -157,7 +159,7 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -323,7 +325,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_2_2_0.py b/kallithea/lib/dbmigrate/schema/db_2_2_0.py --- a/kallithea/lib/dbmigrate/schema/db_2_2_0.py +++ b/kallithea/lib/dbmigrate/schema/db_2_2_0.py @@ -60,6 +60,8 @@ from kallithea.model.meta import Base, S URL_SEP = '/' log = logging.getLogger(__name__) +from kallithea import SETTINGS_PREFIX + #============================================================================== # BASE CLASSES #============================================================================== @@ -158,7 +160,7 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -324,7 +326,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/schema/db_2_2_3.py b/kallithea/lib/dbmigrate/schema/db_2_2_3.py --- a/kallithea/lib/dbmigrate/schema/db_2_2_3.py +++ b/kallithea/lib/dbmigrate/schema/db_2_2_3.py @@ -60,6 +60,8 @@ from kallithea.model.meta import Base, S URL_SEP = '/' log = logging.getLogger(__name__) +from kallithea import SETTINGS_PREFIX + #============================================================================== # BASE CLASSES #============================================================================== @@ -158,7 +160,7 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -324,7 +326,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB', diff --git a/kallithea/lib/dbmigrate/versions/001_initial_release.py b/kallithea/lib/dbmigrate/versions/001_initial_release.py --- a/kallithea/lib/dbmigrate/versions/001_initial_release.py +++ b/kallithea/lib/dbmigrate/versions/001_initial_release.py @@ -12,10 +12,12 @@ from kallithea.model.meta import Base from kallithea.lib.dbmigrate.migrate import * +from kallithea import SETTINGS_PREFIX + log = logging.getLogger(__name__) class Setting(Base): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' __table_args__ = (UniqueConstraint('app_settings_name'), {'useexisting':True}) app_settings_id = Column("app_settings_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) app_settings_name = Column("app_settings_name", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) @@ -30,7 +32,7 @@ class Setting(Base): self.app_settings_value) class Ui(Base): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = {'useexisting':True} ui_id = Column("ui_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) ui_section = Column("ui_section", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -57,6 +57,8 @@ from kallithea.lib.caching_query import from kallithea.model.meta import Base, Session +from kallithea import SETTINGS_PREFIX + URL_SEP = '/' log = logging.getLogger(__name__) @@ -158,7 +160,8 @@ class BaseModel(object): class Setting(Base, BaseModel): - __tablename__ = 'rhodecode_settings' + __tablename__ = SETTINGS_PREFIX + 'settings' + __table_args__ = ( UniqueConstraint('app_settings_name'), {'extend_existing': True, 'mysql_engine': 'InnoDB', @@ -324,7 +327,7 @@ class Setting(Base, BaseModel): class Ui(Base, BaseModel): - __tablename__ = 'rhodecode_ui' + __tablename__ = SETTINGS_PREFIX + 'ui' __table_args__ = ( UniqueConstraint('ui_key'), {'extend_existing': True, 'mysql_engine': 'InnoDB',