From b0672c09fa4af99125489c2c0d91e3c351f7352b Mon Sep 17 00:00:00 2001 From: Marcin Kuzminski Date: Thu, 9 Nov 2017 20:55:02 +0100 Subject: [PATCH] core: ported upgrade-db cli command to pyramid. --- rhodecode/lib/db_manage.py | 4 ++-- rhodecode/lib/dbmigrate/__init__.py | 15 ++++---------- rhodecode/lib/rc_commands/upgrade_db.py | 27 ++++++++++++++++++++----- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/rhodecode/lib/db_manage.py b/rhodecode/lib/db_manage.py index 6b330660..abf55908 100644 --- a/rhodecode/lib/db_manage.py +++ b/rhodecode/lib/db_manage.py @@ -60,14 +60,14 @@ def notify(msg): class DbManage(object): def __init__(self, log_sql, dbconf, root, tests=False, - SESSION=None, cli_args={}): + SESSION=None, cli_args=None): self.dbname = dbconf.split('/')[-1] self.tests = tests self.root = root self.dburi = dbconf self.log_sql = log_sql self.db_exists = False - self.cli_args = cli_args + self.cli_args = cli_args or {} self.init_db(SESSION=SESSION) self.ask_ok = self.get_ask_ok_func(self.cli_args.get('force_ask')) diff --git a/rhodecode/lib/dbmigrate/__init__.py b/rhodecode/lib/dbmigrate/__init__.py index d9216736..2f3d6974 100644 --- a/rhodecode/lib/dbmigrate/__init__.py +++ b/rhodecode/lib/dbmigrate/__init__.py @@ -24,8 +24,7 @@ Database migration modules import logging -from rhodecode.lib.utils import BasePasterCommand, Command, add_cache -from rhodecode.lib.db_manage import DbManage +from rhodecode.lib.utils import BasePasterCommand, Command log = logging.getLogger(__name__) @@ -44,15 +43,9 @@ class UpgradeDb(BasePasterCommand): parser = Command.standard_parser(verbose=True) def command(self): - from pylons import config - add_cache(config) - self.logging_file_config(self.path_to_ini_file) - - db_uri = config['sqlalchemy.db1.url'] - dbmanage = DbManage(log_sql=True, dbconf=db_uri, - root=config['here'], tests=False, - cli_args=self.options.__dict__) - dbmanage.upgrade() + from rhodecode.lib.rc_commands import upgrade_db + upgrade_db.command( + self.path_to_ini_file, self.options.__dict__.get('force_ask')) def update_parser(self): self.parser.add_option('--sql', diff --git a/rhodecode/lib/rc_commands/upgrade_db.py b/rhodecode/lib/rc_commands/upgrade_db.py index b679b227..00f0a27b 100644 --- a/rhodecode/lib/rc_commands/upgrade_db.py +++ b/rhodecode/lib/rc_commands/upgrade_db.py @@ -18,18 +18,35 @@ # RhodeCode Enterprise Edition, including its added features, Support services, # and proprietary license terms, please see https://rhodecode.com/licenses/ +import logging + import click +import pyramid.paster from rhodecode.lib.pyramid_utils import bootstrap -import pyramid.paster +from rhodecode.lib.db_manage import DbManage + +log = logging.getLogger(__name__) @click.command() @click.argument('ini_path', type=click.Path(exists=True)) -def main(ini_path): +@click.option('--force-yes/--force-no', default=None, + help="Force yes/no to every question") +def main(ini_path, force_yes): + return command(ini_path, force_yes) + + +def command(ini_path, force_yes): pyramid.paster.setup_logging(ini_path) with bootstrap(ini_path) as env: - print(env['request'].application_url) - - + config = env['registry'].settings + db_uri = config['sqlalchemy.db1.url'] + options = {} + if force_yes is not None: + options['force_ask'] = force_yes + dbmanage = DbManage( + log_sql=True, dbconf=db_uri, root='.', tests=False, + cli_args=options) + dbmanage.upgrade()