# HG changeset patch # User Thomas De Schampheleire # Date 2016-08-22 17:50:51 # Node ID f973b866fffc1cacbaa840641b1f7d8491a19bb5 # Parent 591effa1fc4dbef696b0a08f8aba6e2e74e0cea8 Turbogears2 migration: use sqlalchemy.url iso sqlalchemy.db1.url In Turbogears2, much of the application initialization is handled by the framework, whereas in Pylons the application was responsible for it. Initializing SQLAlchemy is one such part of initialization which is handled by Turbogears2. Turbogears2 expects the configuration file to refer to the database using 'sqlalchemy.url' rather than the current 'sqlalchemy.db1.url'. While the exact name is not really important, not following this approach means we'll need to override the sqlalchemy initialization method. Therefore, as a preparation to the Turbogears2 migration, already change the database reference string under Pylons. When upgrading to a version of Kallithea containing this commit, the .ini file will manually need to be adapted to remove the .db1 strings. diff --git a/development.ini b/development.ini --- a/development.ini +++ b/development.ini @@ -484,18 +484,18 @@ logview.pylons.util = #eee ######################################################### # SQLITE [default] -sqlalchemy.db1.url = sqlite:///%(here)s/kallithea.db?timeout=60 +sqlalchemy.url = sqlite:///%(here)s/kallithea.db?timeout=60 # POSTGRESQL -#sqlalchemy.db1.url = postgresql://user:pass@localhost/kallithea +#sqlalchemy.url = postgresql://user:pass@localhost/kallithea # MySQL -#sqlalchemy.db1.url = mysql://user:pass@localhost/kallithea?charset=utf8 +#sqlalchemy.url = mysql://user:pass@localhost/kallithea?charset=utf8 # see sqlalchemy docs for others -sqlalchemy.db1.echo = false -sqlalchemy.db1.pool_recycle = 3600 +sqlalchemy.echo = false +sqlalchemy.pool_recycle = 3600 ################################ ### ALEMBIC CONFIGURATION #### diff --git a/docs/upgrade.rst b/docs/upgrade.rst --- a/docs/upgrade.rst +++ b/docs/upgrade.rst @@ -54,7 +54,7 @@ utility. If using MySQL, please consult the documentation for the ``mysqldump`` utility. -Look for ``sqlalchemy.db1.url`` in your configuration file to determine +Look for ``sqlalchemy.url`` in your configuration file to determine database type, settings, location, etc. diff --git a/kallithea/alembic/env.py b/kallithea/alembic/env.py --- a/kallithea/alembic/env.py +++ b/kallithea/alembic/env.py @@ -31,7 +31,7 @@ config = context.config # [alembic] sqlalchemy.url. database_url = ( config.get_main_option('sqlalchemy.url') or - config.get_section_option('app:main', 'sqlalchemy.db1.url') + config.get_section_option('app:main', 'sqlalchemy.url') ) # Configure default logging for Alembic. (This can be overriden by the diff --git a/kallithea/bin/template.ini.mako b/kallithea/bin/template.ini.mako --- a/kallithea/bin/template.ini.mako +++ b/kallithea/bin/template.ini.mako @@ -484,21 +484,21 @@ logview.pylons.util = #eee %if database_engine == 'sqlite': # SQLITE [default] -sqlalchemy.db1.url = sqlite:///${here}/kallithea.db?timeout=60 +sqlalchemy.url = sqlite:///${here}/kallithea.db?timeout=60 %elif database_engine == 'postgres': # POSTGRESQL -sqlalchemy.db1.url = postgresql://user:pass@localhost/kallithea +sqlalchemy.url = postgresql://user:pass@localhost/kallithea %elif database_engine == 'mysql': # MySQL -sqlalchemy.db1.url = mysql://user:pass@localhost/kallithea?charset=utf8 +sqlalchemy.url = mysql://user:pass@localhost/kallithea?charset=utf8 %endif # see sqlalchemy docs for others -sqlalchemy.db1.echo = false -sqlalchemy.db1.pool_recycle = 3600 +sqlalchemy.echo = false +sqlalchemy.pool_recycle = 3600 <%text>################################ <%text>### ALEMBIC CONFIGURATION #### diff --git a/kallithea/config/deployment.ini_tmpl b/kallithea/config/deployment.ini_tmpl --- a/kallithea/config/deployment.ini_tmpl +++ b/kallithea/config/deployment.ini_tmpl @@ -476,18 +476,18 @@ logview.pylons.util = #eee ######################################################### # SQLITE [default] -sqlalchemy.db1.url = sqlite:///%(here)s/kallithea.db?timeout=60 +sqlalchemy.url = sqlite:///%(here)s/kallithea.db?timeout=60 # POSTGRESQL -#sqlalchemy.db1.url = postgresql://user:pass@localhost/kallithea +#sqlalchemy.url = postgresql://user:pass@localhost/kallithea # MySQL -#sqlalchemy.db1.url = mysql://user:pass@localhost/kallithea?charset=utf8 +#sqlalchemy.url = mysql://user:pass@localhost/kallithea?charset=utf8 # see sqlalchemy docs for others -sqlalchemy.db1.echo = false -sqlalchemy.db1.pool_recycle = 3600 +sqlalchemy.echo = false +sqlalchemy.pool_recycle = 3600 ################################ ### ALEMBIC CONFIGURATION #### diff --git a/kallithea/config/environment.py b/kallithea/config/environment.py --- a/kallithea/config/environment.py +++ b/kallithea/config/environment.py @@ -93,7 +93,7 @@ def load_environment(global_conf, app_co test_index = not int(os.environ.get('KALLITHEA_WHOOSH_TEST_DISABLE', 0)) if os.environ.get('TEST_DB'): # swap config if we pass enviroment variable - config['sqlalchemy.db1.url'] = os.environ.get('TEST_DB') + config['sqlalchemy.url'] = os.environ.get('TEST_DB') from kallithea.lib.utils import create_test_env, create_test_index from kallithea.tests import TESTS_TMP_PATH @@ -107,8 +107,8 @@ def load_environment(global_conf, app_co # MULTIPLE DB configs # Setup the SQLAlchemy database engine - sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') - init_model(sa_engine_db1) + sa_engine = engine_from_config(config, 'sqlalchemy.') + init_model(sa_engine) set_available_permissions(config) repos_path = make_ui('db').configitems('paths')[0][1] diff --git a/kallithea/lib/celerylib/__init__.py b/kallithea/lib/celerylib/__init__.py --- a/kallithea/lib/celerylib/__init__.py +++ b/kallithea/lib/celerylib/__init__.py @@ -122,7 +122,7 @@ def locked_task(func): def get_session(): if CELERY_ON: - engine = engine_from_config(config, 'sqlalchemy.db1.') + engine = engine_from_config(config, 'sqlalchemy.') init_model(engine) sa = meta.Session() return sa diff --git a/kallithea/lib/hooks.py b/kallithea/lib/hooks.py --- a/kallithea/lib/hooks.py +++ b/kallithea/lib/hooks.py @@ -395,7 +395,7 @@ def handle_git_receive(repo_path, revs, load_environment(conf.global_conf, conf.local_conf, test_env=False, test_index=False) - engine = engine_from_config(conf, 'sqlalchemy.db1.') + engine = engine_from_config(conf, 'sqlalchemy.') init_model(engine) baseui = make_ui('db') diff --git a/kallithea/lib/paster_commands/common.py b/kallithea/lib/paster_commands/common.py --- a/kallithea/lib/paster_commands/common.py +++ b/kallithea/lib/paster_commands/common.py @@ -103,5 +103,5 @@ class BasePasterCommand(Command): from kallithea.model import init_model from kallithea.lib.utils2 import engine_from_config setup_cache_regions(config) - engine = engine_from_config(config, 'sqlalchemy.db1.') + engine = engine_from_config(config, 'sqlalchemy.') init_model(engine) diff --git a/kallithea/lib/utils.py b/kallithea/lib/utils.py --- a/kallithea/lib/utils.py +++ b/kallithea/lib/utils.py @@ -632,7 +632,7 @@ def create_test_env(repos_test_path, con from kallithea.tests import HG_REPO, GIT_REPO, TESTS_TMP_PATH # PART ONE create db - dbconf = config['sqlalchemy.db1.url'] + dbconf = config['sqlalchemy.url'] log.debug('making test db %s', dbconf) # create test dir if it doesn't exist diff --git a/kallithea/tests/scripts/manual_test_concurrency.py b/kallithea/tests/scripts/manual_test_concurrency.py --- a/kallithea/tests/scripts/manual_test_concurrency.py +++ b/kallithea/tests/scripts/manual_test_concurrency.py @@ -82,7 +82,7 @@ class Command(object): def get_session(): - engine = engine_from_config(conf, 'sqlalchemy.db1.') + engine = engine_from_config(conf, 'sqlalchemy.') init_model(engine) sa = meta.Session return sa diff --git a/kallithea/tests/test.ini b/kallithea/tests/test.ini --- a/kallithea/tests/test.ini +++ b/kallithea/tests/test.ini @@ -488,19 +488,19 @@ logview.pylons.util = #eee ######################################################### # SQLITE [default] -#sqlalchemy.db1.url = sqlite:///%(here)s/kallithea.db?timeout=60 -sqlalchemy.db1.url = sqlite:///%(here)s/kallithea_test.sqlite +#sqlalchemy.url = sqlite:///%(here)s/kallithea.db?timeout=60 +sqlalchemy.url = sqlite:///%(here)s/kallithea_test.sqlite # POSTGRESQL -#sqlalchemy.db1.url = postgresql://user:pass@localhost/kallithea +#sqlalchemy.url = postgresql://user:pass@localhost/kallithea # MySQL -#sqlalchemy.db1.url = mysql://user:pass@localhost/kallithea?charset=utf8 +#sqlalchemy.url = mysql://user:pass@localhost/kallithea?charset=utf8 # see sqlalchemy docs for others -sqlalchemy.db1.echo = false -sqlalchemy.db1.pool_recycle = 3600 +sqlalchemy.echo = false +sqlalchemy.pool_recycle = 3600 ################################ ### ALEMBIC CONFIGURATION #### diff --git a/kallithea/websetup.py b/kallithea/websetup.py --- a/kallithea/websetup.py +++ b/kallithea/websetup.py @@ -37,7 +37,7 @@ log = logging.getLogger(__name__) def setup_app(command, conf, vars): """Place any commands to setup kallithea here""" - dbconf = conf['sqlalchemy.db1.url'] + dbconf = conf['sqlalchemy.url'] dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=conf['here'], tests=False, cli_args=command.options.__dict__) dbmanage.create_tables(override=True) diff --git a/scripts/dbmigrate-test b/scripts/dbmigrate-test old mode 100755 new mode 100644 --- a/scripts/dbmigrate-test +++ b/scripts/dbmigrate-test @@ -65,7 +65,7 @@ temp=$(readlink -f "$(mktemp --tmpdir -d cat <