-GRANT SELECT on placex to "www-data" ;
-GRANT UPDATE ON placex to "www-data" ;
-GRANT SELECT ON search_name to "www-data" ;
-GRANT DELETE on search_name to "www-data" ;
-GRANT INSERT on search_name to "www-data" ;
-GRANT SELECT on place_addressline to "www-data" ;
-GRANT INSERT ON place_addressline to "www-data" ;
-GRANT DELETE on place_addressline to "www-data" ;
-GRANT SELECT ON seq_word to "www-data" ;
-GRANT UPDATE ON seq_word to "www-data" ;
-GRANT INSERT ON word to "www-data" ;
-GRANT SELECT ON planet_osm_ways to "www-data" ;
-GRANT SELECT ON planet_osm_rels to "www-data" ;
-GRANT SELECT on location_area to "www-data" ;
-GRANT SELECT on country to "www-data" ;
-
--- insert creates the location tagbles, creates location indexes if indexed == true
-CREATE TRIGGER placex_before_insert BEFORE INSERT ON placex
- FOR EACH ROW EXECUTE PROCEDURE placex_insert();
-
--- update insert creates the location tables
-CREATE TRIGGER placex_before_update BEFORE UPDATE ON placex
- FOR EACH ROW EXECUTE PROCEDURE placex_update();
-
--- diff update triggers
-CREATE TRIGGER placex_before_delete AFTER DELETE ON placex
- FOR EACH ROW EXECUTE PROCEDURE placex_delete();
-CREATE TRIGGER place_before_delete BEFORE DELETE ON place
- FOR EACH ROW EXECUTE PROCEDURE place_delete();
-CREATE TRIGGER place_before_insert BEFORE INSERT ON place
- FOR EACH ROW EXECUTE PROCEDURE place_insert();
-
-drop index idx_placex_sector;
-CREATE INDEX idx_placex_sector ON placex USING BTREE (geometry_sector,rank_address,osm_type,osm_id);
-
-DROP SEQUENCE seq_postcodes;
-CREATE SEQUENCE seq_postcodes start 1;
+GRANT SELECT on placex to "{www-user}" ;
+GRANT SELECT ON search_name to "{www-user}" ;
+GRANT SELECT on place_addressline to "{www-user}" ;
+GRANT SELECT ON seq_word to "{www-user}" ;
+GRANT SELECT ON planet_osm_ways to "{www-user}" ;
+GRANT SELECT ON planet_osm_rels to "{www-user}" ;
+GRANT SELECT on location_area to "{www-user}" ;
+
+-- Table for synthetic postcodes.
+DROP TABLE IF EXISTS location_postcode;
+CREATE TABLE location_postcode (
+ place_id BIGINT,
+ parent_place_id BIGINT,
+ rank_search SMALLINT,
+ rank_address SMALLINT,
+ indexed_status SMALLINT,
+ indexed_date TIMESTAMP,
+ country_code varchar(2),
+ postcode TEXT,
+ geometry GEOMETRY(Geometry, 4326)
+ );
+CREATE INDEX idx_postcode_geometry ON location_postcode USING GIST (geometry) {ts:address-index};
+GRANT SELECT ON location_postcode TO "{www-user}" ;