From e2330ff4c1183d0319a1e5b428e857a8b3ca8611 Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Thu, 23 Oct 2025 17:23:06 +0200 Subject: [PATCH] add migration for separate entrance table --- src/nominatim_db/tools/migration.py | 57 ++++++++++++++++++----------- src/nominatim_db/version.py | 2 +- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/nominatim_db/tools/migration.py b/src/nominatim_db/tools/migration.py index 85a0c811..5763a694 100644 --- a/src/nominatim_db/tools/migration.py +++ b/src/nominatim_db/tools/migration.py @@ -120,26 +120,39 @@ def create_postcode_parent_index(conn: Connection, **_: Any) -> None: @_migration(5, 1, 99, 0) def create_placex_entrance_table(conn: Connection, config: Configuration, **_: Any) -> None: - """ Add the placex_entrance table to store entrance nodes + """ Add the placex_entrance table to store linked-up entrance nodes """ - sqlp = SQLPreprocessor(conn, config) - sqlp.run_string(conn, """ - -- Table to store location of entrance nodes - DROP TABLE IF EXISTS placex_entrance; - CREATE TABLE placex_entrance ( - place_id BIGINT NOT NULL, - osm_id BIGINT NOT NULL, - type TEXT NOT NULL, - location GEOMETRY(Point, 4326) NOT NULL, - extratags HSTORE - ); - CREATE UNIQUE INDEX idx_placex_entrance_place_id_osm_id ON placex_entrance - USING BTREE (place_id, osm_id) {{db.tablespace.search_index}}; - GRANT SELECT ON placex_entrance TO "{{config.DATABASE_WEBUSER}}" ; - - -- Create an index on the place table for lookups to populate the entrance - -- table - CREATE INDEX IF NOT EXISTS idx_placex_entrance_lookup ON place - USING BTREE (osm_id) - WHERE class IN ('routing:entrance', 'entrance'); - """) + if not table_exists(conn, 'placex_entrance'): + sqlp = SQLPreprocessor(conn, config) + sqlp.run_string(conn, """ + -- Table to store location of entrance nodes + CREATE TABLE placex_entrance ( + place_id BIGINT NOT NULL, + osm_id BIGINT NOT NULL, + type TEXT NOT NULL, + location GEOMETRY(Point, 4326) NOT NULL, + extratags HSTORE + ); + CREATE UNIQUE INDEX idx_placex_entrance_place_id_osm_id ON placex_entrance + USING BTREE (place_id, osm_id) {{db.tablespace.search_index}}; + GRANT SELECT ON placex_entrance TO "{{config.DATABASE_WEBUSER}}" ; + """) + + +@_migration(5, 1, 99, 1) +def create_place_entrance_table(conn: Connection, config: Configuration, **_: Any) -> None: + """ Add the place_entrance table to store incomming entrance nodes + """ + if not table_exists(conn, 'place_entrance'): + with conn.cursor() as cur: + cur.execute(""" + -- Table to store location of entrance nodes + CREATE TABLE place_entrance ( + osm_id BIGINT NOT NULL, + type TEXT NOT NULL, + extratags HSTORE, + geometry GEOMETRY(Point, 4326) NOT NULL + ); + CREATE UNIQUE INDEX place_entrance_osm_id_idx ON place_entrance + USING BTREE (osm_id); + """) diff --git a/src/nominatim_db/version.py b/src/nominatim_db/version.py index 13d83af8..0c5027cf 100644 --- a/src/nominatim_db/version.py +++ b/src/nominatim_db/version.py @@ -55,7 +55,7 @@ def parse_version(version: str) -> NominatimVersion: return NominatimVersion(*[int(x) for x in parts[:2] + parts[2].split('-')]) -NOMINATIM_VERSION = parse_version('5.1.99-0') +NOMINATIM_VERSION = parse_version('5.1.99-1') POSTGRESQL_REQUIRED_VERSION = (12, 0) POSTGIS_REQUIRED_VERSION = (3, 0) -- 2.39.5