mirror of
https://github.com/osm-search/Nominatim.git
synced 2024-09-11 19:17:17 +03:00
Merge pull request #3238 from mtmail/check-database-for-version-match
admin --check-database also checks database vs nominatim version
This commit is contained in:
commit
dc52d0954e
@ -13,9 +13,11 @@ from textwrap import dedent
|
||||
|
||||
from nominatim.config import Configuration
|
||||
from nominatim.db.connection import connect, Connection
|
||||
from nominatim.db import properties
|
||||
from nominatim.errors import UsageError
|
||||
from nominatim.tokenizer import factory as tokenizer_factory
|
||||
from nominatim.tools import freeze
|
||||
from nominatim.version import NOMINATIM_VERSION, parse_version
|
||||
|
||||
CHECKLIST = []
|
||||
|
||||
@ -146,11 +148,52 @@ def check_connection(conn: Any, config: Configuration) -> CheckResult:
|
||||
|
||||
return CheckState.OK
|
||||
|
||||
@_check(hint="""\
|
||||
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}
|
||||
""")
|
||||
def check_database_version(conn: Connection, config: Configuration) -> CheckResult:
|
||||
""" Checking database_version matches Nominatim software version
|
||||
"""
|
||||
|
||||
if conn.table_exists('nominatim_properties'):
|
||||
db_version_str = properties.get_property(conn, 'database_version')
|
||||
else:
|
||||
db_version_str = None
|
||||
|
||||
if db_version_str is not None:
|
||||
db_version = parse_version(db_version_str)
|
||||
|
||||
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 = ''
|
||||
|
||||
return CheckState.FATAL, dict(db_version=db_version_str,
|
||||
nom_version=NOMINATIM_VERSION,
|
||||
instruction=instruction,
|
||||
config=config)
|
||||
|
||||
@_check(hint="""\
|
||||
placex table not found
|
||||
|
||||
Hints:
|
||||
* Are you connecting to the right database?
|
||||
* Are you connecting to the correct database?
|
||||
* Did the import process finish without errors?
|
||||
|
||||
Project directory: {config.project_dir}
|
||||
|
@ -10,6 +10,7 @@ Tests for database integrity checks.
|
||||
import pytest
|
||||
|
||||
from nominatim.tools import check_database as chkdb
|
||||
import nominatim.version
|
||||
|
||||
def test_check_database_unknown_db(def_config, monkeypatch):
|
||||
monkeypatch.setenv('NOMINATIM_DATABASE_DSN', 'pgsql:dbname=fjgkhughwgh2423gsags')
|
||||
@ -20,15 +21,25 @@ def test_check_database_fatal_test(def_config, temp_db):
|
||||
assert chkdb.check_database(def_config) == 1
|
||||
|
||||
|
||||
def test_check_conection_good(temp_db_conn, def_config):
|
||||
def test_check_connection_good(temp_db_conn, def_config):
|
||||
assert chkdb.check_connection(temp_db_conn, def_config) == chkdb.CheckState.OK
|
||||
|
||||
|
||||
def test_check_conection_bad(def_config):
|
||||
def test_check_connection_bad(def_config):
|
||||
badconn = chkdb._BadConnection('Error')
|
||||
assert chkdb.check_connection(badconn, def_config) == chkdb.CheckState.FATAL
|
||||
|
||||
|
||||
def test_check_database_version_good(property_table, temp_db_conn, def_config):
|
||||
property_table.set('database_version',
|
||||
'{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(nominatim.version.NOMINATIM_VERSION))
|
||||
assert chkdb.check_database_version(temp_db_conn, def_config) == chkdb.CheckState.OK
|
||||
|
||||
def test_check_database_version_bad(property_table, temp_db_conn, def_config):
|
||||
property_table.set('database_version', '3.9.9-9')
|
||||
assert chkdb.check_database_version(temp_db_conn, def_config) == chkdb.CheckState.FATAL
|
||||
|
||||
|
||||
def test_check_placex_table_good(table_factory, temp_db_conn, def_config):
|
||||
table_factory('placex')
|
||||
assert chkdb.check_placex_table(temp_db_conn, def_config) == chkdb.CheckState.OK
|
||||
|
Loading…
Reference in New Issue
Block a user