+import logging
from itertools import chain
import psycopg2.extras
from place_inserter import PlaceColumn
from table_compare import NominatimID, DBRow
+from nominatim.indexer import indexer
def check_database_integrity(context):
""" Check some generic constraints on the tables.
""" Import data previously set up in the place table.
"""
context.nominatim.copy_from_place(context.db)
- context.nominatim.run_setup_script('calculate-postcodes', 'index', 'index-noanalyse')
+
+ # XXX use tool function as soon as it is ported
+ with context.db.cursor() as cur:
+ with (context.nominatim.src_dir / 'lib-sql' / 'postcode_tables.sql').open('r') as fd:
+ cur.execute(fd.read())
+ cur.execute("""
+ INSERT INTO location_postcode
+ (place_id, indexed_status, country_code, postcode, geometry)
+ SELECT nextval('seq_place'), 1, country_code,
+ upper(trim (both ' ' from address->'postcode')) as pc,
+ ST_Centroid(ST_Collect(ST_Centroid(geometry)))
+ FROM placex
+ WHERE address ? 'postcode' AND address->'postcode' NOT SIMILAR TO '%(,|;)%'
+ AND geometry IS NOT null
+ GROUP BY country_code, pc""")
+
+ # Call directly as the refresh function does not include postcodes.
+ indexer.LOG.setLevel(logging.ERROR)
+ indexer.Indexer(context.nominatim.get_libpq_dsn(), 1).index_full(analyse=False)
+
check_database_integrity(context)
@when("updating places")
""" Update the place table with the given data. Also runs all triggers
related to updates and reindexes the new data.
"""
- context.nominatim.run_setup_script(
- 'create-functions', 'create-partition-functions', 'enable-diff-updates')
+ context.nominatim.run_nominatim('refresh', '--functions')
with context.db.cursor() as cur:
for row in context.table:
PlaceColumn(context).add_row(row, False).db_insert(cur)
def update_postcodes(context):
""" Rerun the calculation of postcodes.
"""
- context.nominatim.run_update_script('calculate-postcodes')
+ context.nominatim.run_nominatim('refresh', '--postcodes')
@when("marking for delete (?P<oids>.*)")
def delete_places(context, oids):
separated by commas. Also runs all triggers
related to updates and reindexes the new data.
"""
- context.nominatim.run_setup_script(
- 'create-functions', 'create-partition-functions', 'enable-diff-updates')
+ context.nominatim.run_nominatim('refresh', '--functions')
with context.db.cursor() as cur:
for oid in oids.split(','):
NominatimID(oid).query_osm_id(cur, 'DELETE FROM place WHERE {}')