Show More
@@ -66,11 +66,23 b' class DbManage(object):' | |||
|
66 | 66 | self.root = root |
|
67 | 67 | self.dburi = dbconf |
|
68 | 68 | self.log_sql = log_sql |
|
69 | self.db_exists = False | |
|
70 | 69 | self.cli_args = cli_args or {} |
|
71 | 70 | self.init_db(SESSION=SESSION) |
|
72 | 71 | self.ask_ok = self.get_ask_ok_func(self.cli_args.get('force_ask')) |
|
73 | 72 | |
|
73 | def db_exists(self): | |
|
74 | if not self.sa: | |
|
75 | self.init_db() | |
|
76 | try: | |
|
77 | self.sa.query(RhodeCodeUi)\ | |
|
78 | .filter(RhodeCodeUi.ui_key == '/')\ | |
|
79 | .scalar() | |
|
80 | return True | |
|
81 | except Exception: | |
|
82 | return False | |
|
83 | finally: | |
|
84 | self.sa.rollback() | |
|
85 | ||
|
74 | 86 | def get_ask_ok_func(self, param): |
|
75 | 87 | if param not in [None]: |
|
76 | 88 | # return a function lambda that has a default set to param |
@@ -60,14 +60,24 b' log = logging.getLogger(__name__)' | |||
|
60 | 60 | default=None, |
|
61 | 61 | help='Enable public access on this installation. ' |
|
62 | 62 | 'Default is public access enabled.') |
|
63 | @click.option( | |
|
64 | '--skip-existing-db', | |
|
65 | default=False, | |
|
66 | is_flag=True, | |
|
67 | help='Do not destroy and re-initialize the database if it already exist.') | |
|
68 | @click.option( | |
|
69 | '--apply-license-key', | |
|
70 | default=False, | |
|
71 | is_flag=True, | |
|
72 | help='Get the license key from a license file or ENV and apply during DB creation.') | |
|
63 | 73 | def main(ini_path, force_yes, user, email, password, api_key, repos, |
|
64 | public_access): | |
|
74 | public_access, skip_existing_db, apply_license_key): | |
|
65 | 75 | return command(ini_path, force_yes, user, email, password, api_key, |
|
66 | repos, public_access) | |
|
76 | repos, public_access, skip_existing_db, apply_license_key) | |
|
67 | 77 | |
|
68 | 78 | |
|
69 | 79 | def command(ini_path, force_yes, user, email, password, api_key, repos, |
|
70 | public_access): | |
|
80 | public_access, skip_existing_db, apply_license_key): | |
|
71 | 81 | # mapping of old parameters to new CLI from click |
|
72 | 82 | options = dict( |
|
73 | 83 | username=user, |
@@ -85,6 +95,9 b' def command(ini_path, force_yes, user, e' | |||
|
85 | 95 | db_uri = config['sqlalchemy.db1.url'] |
|
86 | 96 | dbmanage = DbManage(log_sql=True, dbconf=db_uri, root='.', |
|
87 | 97 | tests=False, cli_args=options) |
|
98 | if skip_existing_db and dbmanage.db_exists(): | |
|
99 | return | |
|
100 | ||
|
88 | 101 | dbmanage.create_tables(override=True) |
|
89 | 102 | dbmanage.set_db_version() |
|
90 | 103 | opts = dbmanage.config_prompt(None) |
@@ -93,6 +106,13 b' def command(ini_path, force_yes, user, e' | |||
|
93 | 106 | dbmanage.create_admin_and_prompt() |
|
94 | 107 | dbmanage.create_permissions() |
|
95 | 108 | dbmanage.populate_default_permissions() |
|
109 | if apply_license_key: | |
|
110 | try: | |
|
111 | from rc_license.models import apply_trial_license_if_missing | |
|
112 | apply_trial_license_if_missing(force=True) | |
|
113 | except ImportError: | |
|
114 | pass | |
|
115 | ||
|
96 | 116 | Session().commit() |
|
97 | 117 | |
|
98 | 118 | with bootstrap(ini_path, env={'RC_CMD_SETUP_RC': '1'}) as env: |
General Comments 0
You need to be logged in to leave comments.
Login now