From 89094cf92e82ebb1004498fad8822975f1af4347 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 7 Dec 2023 10:24:53 +0100 Subject: [PATCH] error out when a SQLite database does not exist Requires to mark the databse r/w when it is newly created in the convert function. --- nominatim/api/core.py | 4 ++++ nominatim/tools/convert_sqlite.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/nominatim/api/core.py b/nominatim/api/core.py index f975f44a..1c0c4423 100644 --- a/nominatim/api/core.py +++ b/nominatim/api/core.py @@ -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() diff --git a/nominatim/tools/convert_sqlite.py b/nominatim/tools/convert_sqlite.py index 16139c5f..3e584710 100644 --- a/nominatim/tools/convert_sqlite.py +++ b/nominatim/tools/convert_sqlite.py @@ -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: -- 2.39.5