]> git.openstreetmap.org Git - nominatim.git/blobdiff - src/nominatim_db/tools/check_database.py
Merge pull request #3582 from lonvia/switch-to-flake
[nominatim.git] / src / nominatim_db / tools / check_database.py
index 7389c9a2c8be49bdf7a43f9984427e5f52f00430..79770142494821fc23bee2c63b72940911e43300 100644 (file)
@@ -12,7 +12,7 @@ from enum import Enum
 from textwrap import dedent
 
 from ..config import Configuration
 from textwrap import dedent
 
 from ..config import Configuration
-from ..db.connection import connect, Connection, server_version_tuple,\
+from ..db.connection import connect, Connection, server_version_tuple, \
                             index_exists, table_exists, execute_scalar
 from ..db import properties
 from ..errors import UsageError
                             index_exists, table_exists, execute_scalar
 from ..db import properties
 from ..errors import UsageError
@@ -22,6 +22,7 @@ from ..version import NOMINATIM_VERSION, parse_version
 
 CHECKLIST = []
 
 
 CHECKLIST = []
 
+
 class CheckState(Enum):
     """ Possible states of a check. FATAL stops check execution entirely.
     """
 class CheckState(Enum):
     """ Possible states of a check. FATAL stops check execution entirely.
     """
@@ -31,9 +32,11 @@ class CheckState(Enum):
     NOT_APPLICABLE = 3
     WARN = 4
 
     NOT_APPLICABLE = 3
     WARN = 4
 
+
 CheckResult = Union[CheckState, Tuple[CheckState, Mapping[str, Any]]]
 CheckFunc = Callable[[Connection, Configuration], CheckResult]
 
 CheckResult = Union[CheckState, Tuple[CheckState, Mapping[str, Any]]]
 CheckFunc = Callable[[Connection, Configuration], CheckResult]
 
+
 def _check(hint: Optional[str] = None) -> Callable[[CheckFunc], CheckFunc]:
     """ Decorator for checks. It adds the function to the list of
         checks to execute and adds the code for printing progress messages.
 def _check(hint: Optional[str] = None) -> Callable[[CheckFunc], CheckFunc]:
     """ Decorator for checks. It adds the function to the list of
         checks to execute and adds the code for printing progress messages.
@@ -68,6 +71,7 @@ def _check(hint: Optional[str] = None) -> Callable[[CheckFunc], CheckFunc]:
 
     return decorator
 
 
     return decorator
 
+
 class _BadConnection:
 
     def __init__(self, msg: str) -> None:
 class _BadConnection:
 
     def __init__(self, msg: str) -> None:
@@ -77,13 +81,14 @@ class _BadConnection:
         """ Dummy function to provide the implementation.
         """
 
         """ Dummy function to provide the implementation.
         """
 
+
 def check_database(config: Configuration) -> int:
     """ Run a number of checks on the database and return the status.
     """
     try:
         conn = connect(config.get_libpq_dsn())
     except UsageError as err:
 def check_database(config: Configuration) -> int:
     """ Run a number of checks on the database and return the status.
     """
     try:
         conn = connect(config.get_libpq_dsn())
     except UsageError as err:
-        conn = _BadConnection(str(err)) # type: ignore[assignment]
+        conn = _BadConnection(str(err))  # type: ignore[assignment]
 
     overall_result = 0
     for check in CHECKLIST:
 
     overall_result = 0
     for check in CHECKLIST:
@@ -103,13 +108,16 @@ def _get_indexes(conn: Connection) -> List[str]:
                'idx_placex_rank_search',
                'idx_placex_rank_address',
                'idx_placex_parent_place_id',
                'idx_placex_rank_search',
                'idx_placex_rank_address',
                'idx_placex_parent_place_id',
+               'idx_placex_geometry_reverse_lookupplacenode',
                'idx_placex_geometry_reverse_lookuppolygon',
                'idx_placex_geometry_placenode',
                'idx_osmline_parent_place_id',
                'idx_osmline_parent_osm_id',
                'idx_postcode_id',
                'idx_postcode_postcode'
                'idx_placex_geometry_reverse_lookuppolygon',
                'idx_placex_geometry_placenode',
                'idx_osmline_parent_place_id',
                'idx_osmline_parent_osm_id',
                'idx_postcode_id',
                'idx_postcode_postcode'
-              ]
+               ]
+
+    # These won't exist if --reverse-only import was used
     if table_exists(conn, 'search_name'):
         indexes.extend(('idx_search_name_nameaddress_vector',
                         'idx_search_name_name_vector',
     if table_exists(conn, 'search_name'):
         indexes.extend(('idx_search_name_nameaddress_vector',
                         'idx_search_name_name_vector',
@@ -117,6 +125,8 @@ def _get_indexes(conn: Connection) -> List[str]:
         if server_version_tuple(conn) >= (11, 0, 0):
             indexes.extend(('idx_placex_housenumber',
                             'idx_osmline_parent_osm_id_with_hnr'))
         if server_version_tuple(conn) >= (11, 0, 0):
             indexes.extend(('idx_placex_housenumber',
                             'idx_osmline_parent_osm_id_with_hnr'))
+
+    # These won't exist if --no-updates import was used
     if table_exists(conn, 'place'):
         indexes.extend(('idx_location_area_country_place_id',
                         'idx_place_osm_unique',
     if table_exists(conn, 'place'):
         indexes.extend(('idx_location_area_country_place_id',
                         'idx_place_osm_unique',
@@ -149,6 +159,7 @@ def check_connection(conn: Any, config: Configuration) -> CheckResult:
 
     return CheckState.OK
 
 
     return CheckState.OK
 
+
 @_check(hint="""\
              Database version ({db_version}) doesn't match Nominatim version ({nom_version})
 
 @_check(hint="""\
              Database version ({db_version}) doesn't match Nominatim version ({nom_version})
 
@@ -190,6 +201,7 @@ def check_database_version(conn: Connection, config: Configuration) -> CheckResu
                                   instruction=instruction,
                                   config=config)
 
                                   instruction=instruction,
                                   config=config)
 
+
 @_check(hint="""\
              placex table not found
 
 @_check(hint="""\
              placex table not found
 
@@ -269,7 +281,7 @@ def check_indexing(conn: Connection, _: Configuration) -> CheckResult:
         return CheckState.OK
 
     if freeze.is_frozen(conn):
         return CheckState.OK
 
     if freeze.is_frozen(conn):
-        index_cmd="""\
+        index_cmd = """\
             Database is marked frozen, it cannot be updated.
             Low counts of unindexed places are fine."""
         return CheckState.WARN, dict(count=cnt, index_cmd=index_cmd)
             Database is marked frozen, it cannot be updated.
             Low counts of unindexed places are fine."""
         return CheckState.WARN, dict(count=cnt, index_cmd=index_cmd)