diff --git a/swh/core/cli/db.py b/swh/core/cli/db.py --- a/swh/core/cli/db.py +++ b/swh/core/cli/db.py @@ -389,13 +389,19 @@ f"{ds_version} of the datastore backend {db_module}" ) - new_db_version = swh_db_upgrade(dbname, module, to_version) - click.secho(f"Migration to version {new_db_version} done", fg="green") - if new_db_version < ds_version: + if to_version == db_version: click.secho( - f"Warning: migration was not complete: the current version is {ds_version}", - fg="yellow", + f"No migration needed: the current version is {db_version}", fg="yellow", ) + else: + new_db_version = swh_db_upgrade(dbname, module, to_version) + click.secho(f"Migration to version {new_db_version} done", fg="green") + if new_db_version < ds_version: + click.secho( + "Warning: migration was not complete: " + f"the current version is {ds_version}", + fg="yellow", + ) def get_dburl_from_config(cfg): diff --git a/swh/core/db/db_utils.py b/swh/core/db/db_utils.py --- a/swh/core/db/db_utils.py +++ b/swh/core/db/db_utils.py @@ -11,7 +11,7 @@ import pathlib import re import subprocess -from typing import Collection, Dict, List, Optional, Tuple, Union +from typing import Collection, Dict, List, Optional, Tuple, Union, cast import psycopg2 import psycopg2.errors @@ -143,7 +143,8 @@ ) try: c.execute(query) - return c.fetchall() + versions = cast(List[Tuple[int, datetime, str]], c.fetchall()) + return versions except psycopg2.errors.UndefinedTable: return None except Exception: @@ -185,6 +186,9 @@ if db_version < int(fname.stem) <= to_version ] + if not sqlfiles: + return db_version + for sqlfile in sqlfiles: new_version = int(path.splitext(path.basename(sqlfile))[0]) logger.info("Executing migration script {sqlfile}")