-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();
-
-alter table placex add column geometry_sector INTEGER;
-alter table placex add column indexed_status INTEGER;
-alter table placex add column indexed_date TIMESTAMP;
-
-update placex set geometry_sector = geometry_sector(geometry);
-drop index idx_placex_pendingbylatlon;
-drop index idx_placex_interpolation;
-drop index idx_placex_sector;
-CREATE INDEX idx_placex_pendingbylatlon ON placex USING BTREE (geometry_index(geometry_sector,indexed,name),rank_search)
- where geometry_index(geometry_sector,indexed,name) IS NOT NULL;
-CREATE INDEX idx_placex_interpolation ON placex USING BTREE (geometry_sector) where indexed = false and class='place' and type='houses';
-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}" ;