diff --git a/bin/utils/db_diff.py b/bin/utils/db_diff.py index 1f92b314228..2e7c86567ce 100644 --- a/bin/utils/db_diff.py +++ b/bin/utils/db_diff.py @@ -112,7 +112,7 @@ def main(dbname, verbose, reverse): _checked_call(verbose, ['createdb', '-T', 'indico_template', temp_dbname]) try: env_override = {'INDICO_CONF_OVERRIDE': repr({'SQLALCHEMY_DATABASE_URI': _build_conn_string(temp_dbname)})} - _checked_call(verbose, ['indico', 'db', 'prepare'], env=env_override) + _checked_call(verbose, ['indico', 'db', 'prepare', '--force'], env=env_override) # create SQLAlchemy engines/connections for base and target db base_eng = create_engine(_build_conn_string(temp_dbname)) diff --git a/indico/cli/database.py b/indico/cli/database.py index a1ea9985a2e..b2178f8d6f4 100644 --- a/indico/cli/database.py +++ b/indico/cli/database.py @@ -45,7 +45,8 @@ def cli(ctx, plugin=None, all_plugins=False): @click.option('--force', is_flag=True, help='Force using an older Postgres version') def prepare(force=False): """Initialize a new database (creates tables, sets alembic rev to HEAD).""" - return prepare_db(force=force) + if not prepare_db(force=force): + sys.exit(1) def _stamp(plugin=None, revision=None): diff --git a/indico/core/db/sqlalchemy/migration.py b/indico/core/db/sqlalchemy/migration.py index a6aff16353c..852a26c2789 100644 --- a/indico/core/db/sqlalchemy/migration.py +++ b/indico/core/db/sqlalchemy/migration.py @@ -81,11 +81,11 @@ def _require_encoding(encoding): def prepare_db(empty=False, root_path=None, verbose=True, force=False): """Initialize an empty database (create tables, set alembic rev to HEAD).""" if not _require_pg_version(13, force=force): - return + return False if not _require_encoding('UTF8'): - return + return False if not _require_extensions('unaccent', 'pg_trgm'): - return + return False root_path = root_path or current_app.root_path tables = get_all_tables(db) if 'alembic_version' not in tables['public']: @@ -116,5 +116,6 @@ def prepare_db(empty=False, root_path=None, verbose=True, force=False): for schema, schema_tables in sorted(tables.items()): for t in schema_tables: print(cformat(' * %{cyan}{}%{reset}.%{cyan!}{}%{reset}').format(schema, t)) - return + return False create_all_tables(db, verbose=verbose, add_initial_data=(not empty)) + return True