]> git.openstreetmap.org Git - nominatim.git/commitdiff
error out when a SQLite database does not exist
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 7 Dec 2023 09:24:53 +0000 (10:24 +0100)
committerSarah Hoffmann <lonvia@denofr.de>
Thu, 7 Dec 2023 09:24:53 +0000 (10:24 +0100)
Requires to mark the databse r/w when it is newly created in the
convert function.

nominatim/api/core.py
nominatim/tools/convert_sqlite.py

index f975f44aaec39b3e358329f67c0c0da70f702017..1c0c4423fcae0c6a82d07c39c690bd1b14ffbb47 100644 (file)
@@ -101,6 +101,10 @@ class NominatimAPIAsync: #pylint: disable=too-many-instance-attributes
                 dburl = sa.engine.URL.create('sqlite+aiosqlite',
                                              database=params.get('dbname'))
 
+                if not ('NOMINATIM_DATABASE_RW' in self.config.environ
+                        and self.config.get_bool('DATABASE_RW')) \
+                   and not Path(params.get('dbname', '')).is_file():
+                    raise UsageError(f"SQlite database '{params.get('dbname')}' does not exist.")
             else:
                 dsn = self.config.get_database_params()
                 query = {k: v for k, v in dsn.items()
index 16139c5fbcf6d41a55dd97f06db1fd8912da4b2a..3e5847107efbd5c10016e03316560581feff165b 100644 (file)
@@ -28,7 +28,8 @@ async def convert(project_dir: Path, outfile: Path, options: Set[str]) -> None:
 
     try:
         outapi = napi.NominatimAPIAsync(project_dir,
-                                        {'NOMINATIM_DATABASE_DSN': f"sqlite:dbname={outfile}"})
+                                        {'NOMINATIM_DATABASE_DSN': f"sqlite:dbname={outfile}",
+                                         'NOMINATIM_DATABASE_RW': '1'})
 
         try:
             async with api.begin() as src, outapi.begin() as dest: