From 9bad3b1e61831efff3922bf67fc3e2c4acf12e29 Mon Sep 17 00:00:00 2001 From: marc tobias Date: Wed, 30 Jul 2025 02:26:22 +0200 Subject: [PATCH] Better hint to user if database import didnt finish --- docs/develop/Development-Environment.md | 2 +- src/nominatim_db/tools/check_database.py | 35 +++++++++++------------- test/python/tools/test_check_database.py | 4 +++ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/docs/develop/Development-Environment.md b/docs/develop/Development-Environment.md index 5f247455..577ccbd0 100644 --- a/docs/develop/Development-Environment.md +++ b/docs/develop/Development-Environment.md @@ -92,7 +92,7 @@ but executes against the code in the source tree. For example: ``` me@machine:~$ cd Nominatim me@machine:~Nominatim$ ./nominatim-cli.py --version -Nominatim version 4.4.99-1 +Nominatim version 5.1.0-0 ``` Make sure you have activated the virtual environment holding all diff --git a/src/nominatim_db/tools/check_database.py b/src/nominatim_db/tools/check_database.py index 4c6f0331..f4020803 100644 --- a/src/nominatim_db/tools/check_database.py +++ b/src/nominatim_db/tools/check_database.py @@ -2,7 +2,7 @@ # # This file is part of Nominatim. (https://nominatim.org) # -# Copyright (C) 2024 by the Nominatim developer community. +# Copyright (C) 2025 by the Nominatim developer community. # For a full list of authors see the git log. """ Collection of functions that check if the database is complete and functional. @@ -163,12 +163,8 @@ def check_connection(conn: Any, config: Configuration) -> CheckResult: Database version ({db_version}) doesn't match Nominatim version ({nom_version}) Hints: - * Are you connecting to the correct database? - {instruction} - Check the Migration chapter of the Administration Guide. - Project directory: {config.project_dir} Current setting of NOMINATIM_DATABASE_DSN: {config.DATABASE_DSN} """) @@ -176,24 +172,25 @@ def check_database_version(conn: Connection, config: Configuration) -> CheckResu """ Checking database_version matches Nominatim software version """ - if table_exists(conn, 'nominatim_properties'): - db_version_str = properties.get_property(conn, 'database_version') + db_version_str = None + if not table_exists(conn, 'nominatim_properties'): + instruction = 'Are you connecting to the correct database?' else: - db_version_str = None + db_version_str = properties.get_property(conn, 'database_version') - if db_version_str is not None: - db_version = parse_version(db_version_str) + if db_version_str is None: + instruction = 'Database version not found. Did the import finish?' + else: + db_version = parse_version(db_version_str) - if db_version == NOMINATIM_VERSION: - return CheckState.OK + if db_version == NOMINATIM_VERSION: + return CheckState.OK - instruction = ( - 'Run migrations: nominatim admin --migrate' - if db_version < NOMINATIM_VERSION - else 'You need to upgrade the Nominatim software.' - ) - else: - instruction = '' + instruction = ( + "Run migrations: 'nominatim admin --migrate'" + if db_version < NOMINATIM_VERSION + else 'You need to upgrade the Nominatim software.' + ) + ' Check the Migration chapter of the Administration Guide.' return CheckState.FATAL, dict(db_version=db_version_str, nom_version=NOMINATIM_VERSION, diff --git a/test/python/tools/test_check_database.py b/test/python/tools/test_check_database.py index 66506f56..532c6031 100644 --- a/test/python/tools/test_check_database.py +++ b/test/python/tools/test_check_database.py @@ -31,6 +31,10 @@ def test_check_connection_bad(def_config): assert chkdb.check_connection(badconn, def_config) == chkdb.CheckState.FATAL +def test_check_database_version_not_found(property_table, temp_db_conn, def_config): + assert chkdb.check_database_version(temp_db_conn, def_config) == chkdb.CheckState.FATAL + + def test_check_database_version_good(property_table, temp_db_conn, def_config): property_table.set('database_version', str(nominatim_db.version.NOMINATIM_VERSION)) -- 2.39.5