Skip to content

Commit

Permalink
error out when a SQLite database does not exist
Browse files Browse the repository at this point in the history
Requires to mark the databse r/w when it is newly created in the
convert function.
  • Loading branch information
lonvia committed Dec 7, 2023
1 parent 3f5484f commit 89094cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions nominatim/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ async def setup_database(self) -> None:
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()
Expand Down
3 changes: 2 additions & 1 deletion nominatim/tools/convert_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 89094cf

Please sign in to comment.