Skip to content

Commit

Permalink
Skip PG version check in db diff util
Browse files Browse the repository at this point in the history
Also exit with a non-zero status code when `indico db prepare` fails
e.g. due to an too-old PG version
  • Loading branch information
ThiefMaster committed Nov 3, 2022
1 parent 4ec8d6c commit f587aa6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/utils/db_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion indico/cli/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions indico/core/db/sqlalchemy/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down Expand Up @@ -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

0 comments on commit f587aa6

Please sign in to comment.