From fff5858b536e5b2de51b92671332231eae2a6e98 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Sat, 21 Feb 2026 12:42:18 +0100 Subject: [PATCH] add option to force a postcode reimport --- src/nominatim_db/clicmd/args.py | 1 + src/nominatim_db/clicmd/refresh.py | 7 ++++++- src/nominatim_db/tools/postcodes.py | 9 +++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/nominatim_db/clicmd/args.py b/src/nominatim_db/clicmd/args.py index a7072d9f..663699c0 100644 --- a/src/nominatim_db/clicmd/args.py +++ b/src/nominatim_db/clicmd/args.py @@ -120,6 +120,7 @@ class NominatimArgs: data_object: Sequence[Tuple[str, int]] data_area: Sequence[Tuple[str, int]] ro_access: bool + postcode_force_reimport: bool # Arguments to 'replication' init: bool diff --git a/src/nominatim_db/clicmd/refresh.py b/src/nominatim_db/clicmd/refresh.py index 96646c1a..fbf32c52 100644 --- a/src/nominatim_db/clicmd/refresh.py +++ b/src/nominatim_db/clicmd/refresh.py @@ -84,6 +84,10 @@ class UpdateRefresh: help='Do not enable code for propagating updates') group.add_argument('--enable-debug-statements', action='store_true', help='Enable debug warning statements in functions') + group = parser.add_argument_group('Arguments for postcode refresh') + group.add_argument('--force-reimport', action='store_true', + dest='postcode_force_reimport', + help='Recompute the postcodes from scratch instead of updating') def run(self, args: NominatimArgs) -> int: from ..tools import refresh, postcodes @@ -96,7 +100,8 @@ class UpdateRefresh: LOG.warning("Update postcodes centroid") tokenizer = self._get_tokenizer(args.config) postcodes.update_postcodes(args.config.get_libpq_dsn(), - args.project_dir, tokenizer) + args.project_dir, tokenizer, + force_reimport=args.postcode_force_reimport) indexer = Indexer(args.config.get_libpq_dsn(), tokenizer, args.threads or 1) asyncio.run(indexer.index_postcodes()) diff --git a/src/nominatim_db/tools/postcodes.py b/src/nominatim_db/tools/postcodes.py index b15b5f1b..219bcd19 100644 --- a/src/nominatim_db/tools/postcodes.py +++ b/src/nominatim_db/tools/postcodes.py @@ -177,7 +177,8 @@ class _PostcodeCollector: return None -def update_postcodes(dsn: str, project_dir: Optional[Path], tokenizer: AbstractTokenizer) -> None: +def update_postcodes(dsn: str, project_dir: Optional[Path], + tokenizer: AbstractTokenizer, force_reimport: bool = False) -> None: """ Update the table of postcodes from the input tables placex and place_postcode. """ @@ -189,7 +190,11 @@ def update_postcodes(dsn: str, project_dir: Optional[Path], tokenizer: AbstractT SET country_code = get_country_code(centroid) WHERE country_code is null """) - is_initial = _is_postcode_table_empty(conn) + if force_reimport: + conn.execute("TRUNCATE location_postcodes") + is_initial = True + else: + is_initial = _is_postcode_table_empty(conn) if is_initial: conn.execute("""ALTER TABLE location_postcodes DISABLE TRIGGER location_postcodes_before_insert""")