1 drop table if exists import_status;
 
   2 CREATE TABLE import_status (
 
   3   lastimportdate timestamp NOT NULL
 
   5 GRANT SELECT ON import_status TO "{www-user}" ;
 
   7 drop table if exists import_osmosis_log;
 
   8 CREATE TABLE import_osmosis_log (
 
  16 CREATE TABLE new_query_log (
 
  29 CREATE INDEX idx_new_query_log_starttime ON new_query_log USING BTREE (starttime);
 
  30 GRANT INSERT ON new_query_log TO "{www-user}" ;
 
  31 GRANT UPDATE ON new_query_log TO "{www-user}" ;
 
  32 GRANT SELECT ON new_query_log TO "{www-user}" ;
 
  34 GRANT SELECT ON TABLE country_name TO "{www-user}";
 
  35 GRANT SELECT ON TABLE gb_postcode TO "{www-user}";
 
  37 drop table IF EXISTS word;
 
  44   country_code varchar(2),
 
  45   search_name_count INTEGER,
 
  48 CREATE INDEX idx_word_word_token on word USING BTREE (word_token) {ts:search-index};
 
  49 GRANT SELECT ON word TO "{www-user}" ;
 
  50 DROP SEQUENCE IF EXISTS seq_word;
 
  51 CREATE SEQUENCE seq_word start 1;
 
  53 drop table IF EXISTS location_area CASCADE;
 
  54 CREATE TABLE location_area (
 
  57   country_code VARCHAR(2),
 
  59   rank_search INTEGER NOT NULL,
 
  60   rank_address INTEGER NOT NULL,
 
  63 SELECT AddGeometryColumn('location_area', 'centroid', 4326, 'POINT', 2);
 
  64 SELECT AddGeometryColumn('location_area', 'geometry', 4326, 'GEOMETRY', 2);
 
  66 CREATE TABLE location_area_large () INHERITS (location_area);
 
  68 drop table IF EXISTS location_property CASCADE;
 
  69 CREATE TABLE location_property (
 
  72   parent_place_id BIGINT,
 
  76 SELECT AddGeometryColumn('location_property', 'centroid', 4326, 'POINT', 2);
 
  78 drop table IF EXISTS search_name;
 
  79 CREATE TABLE search_name (
 
  84   country_code varchar(2),
 
  85   name_vector integer[],
 
  86   nameaddress_vector integer[]
 
  88 SELECT AddGeometryColumn('search_name', 'centroid', 4326, 'GEOMETRY', 2);
 
  89 CREATE INDEX idx_search_name_place_id ON search_name USING BTREE (place_id) {ts:search-index};
 
  91 drop table IF EXISTS place_addressline;
 
  92 CREATE TABLE place_addressline (
 
  94   address_place_id BIGINT,
 
  98   cached_rank_address integer
 
 100 CREATE INDEX idx_place_addressline_place_id on place_addressline USING BTREE (place_id) {ts:search-index};
 
 102 drop table if exists placex;
 
 103 CREATE TABLE placex (
 
 104   place_id BIGINT NOT NULL,
 
 106   LIKE place INCLUDING CONSTRAINTS,
 
 107   parent_place_id BIGINT,
 
 108   linked_place_id BIGINT,
 
 109   rank_address INTEGER,
 
 112   indexed_status INTEGER,
 
 113   indexed_date TIMESTAMP,
 
 114   wikipedia TEXT, -- calculated wikipedia article name (language:title)
 
 115   geometry_sector INTEGER,
 
 116   calculated_country_code varchar(2)
 
 118 SELECT AddGeometryColumn('placex', 'centroid', 4326, 'GEOMETRY', 2);
 
 119 CREATE UNIQUE INDEX idx_place_id ON placex USING BTREE (place_id) {ts:search-index};
 
 120 CREATE INDEX idx_placex_osmid ON placex USING BTREE (osm_type, osm_id) {ts:search-index};
 
 121 CREATE INDEX idx_placex_linked_place_id ON placex USING BTREE (linked_place_id) {ts:address-index};
 
 122 CREATE INDEX idx_placex_rank_search ON placex USING BTREE (rank_search, geometry_sector) {ts:address-index};
 
 123 CREATE INDEX idx_placex_geometry ON placex USING GIST (geometry) {ts:search-index};
 
 124 CREATE INDEX idx_placex_adminname on placex USING BTREE (make_standard_name(name->'name'),rank_search) {ts:address-index} WHERE osm_type='N' and rank_search < 26;
 
 126 DROP SEQUENCE IF EXISTS seq_place;
 
 127 CREATE SEQUENCE seq_place start 1;
 
 128 GRANT SELECT on placex to "{www-user}" ;
 
 129 GRANT SELECT ON search_name to "{www-user}" ;
 
 130 GRANT SELECT on place_addressline to "{www-user}" ;
 
 131 GRANT SELECT ON seq_word to "{www-user}" ;
 
 132 GRANT SELECT ON planet_osm_ways to "{www-user}" ;
 
 133 GRANT SELECT ON planet_osm_rels to "{www-user}" ;
 
 134 GRANT SELECT on location_area to "{www-user}" ;
 
 136 -- insert creates the location tagbles, creates location indexes if indexed == true
 
 137 CREATE TRIGGER placex_before_insert BEFORE INSERT ON placex
 
 138     FOR EACH ROW EXECUTE PROCEDURE placex_insert();
 
 140 -- update insert creates the location tables
 
 141 CREATE TRIGGER placex_before_update BEFORE UPDATE ON placex
 
 142     FOR EACH ROW EXECUTE PROCEDURE placex_update();
 
 144 -- diff update triggers
 
 145 CREATE TRIGGER placex_before_delete AFTER DELETE ON placex
 
 146     FOR EACH ROW EXECUTE PROCEDURE placex_delete();
 
 147 CREATE TRIGGER place_before_delete BEFORE DELETE ON place
 
 148     FOR EACH ROW EXECUTE PROCEDURE place_delete();
 
 149 CREATE TRIGGER place_before_insert BEFORE INSERT ON place
 
 150     FOR EACH ROW EXECUTE PROCEDURE place_insert();
 
 152 DROP SEQUENCE seq_postcodes;
 
 153 CREATE SEQUENCE seq_postcodes start 1;
 
 155 drop table import_polygon_error;
 
 156 CREATE TABLE import_polygon_error (
 
 162   country_code varchar(2),
 
 166 SELECT AddGeometryColumn('import_polygon_error', 'prevgeometry', 4326, 'GEOMETRY', 2);
 
 167 SELECT AddGeometryColumn('import_polygon_error', 'newgeometry', 4326, 'GEOMETRY', 2);
 
 168 CREATE INDEX idx_import_polygon_error_osmid ON import_polygon_error USING BTREE (osm_type, osm_id);
 
 169 GRANT SELECT ON import_polygon_error TO "{www-user}";
 
 171 drop table import_polygon_delete;
 
 172 CREATE TABLE import_polygon_delete (
 
 178 CREATE INDEX idx_import_polygon_delete_osmid ON import_polygon_delete USING BTREE (osm_type, osm_id);
 
 179 GRANT SELECT ON import_polygon_delete TO "{www-user}";
 
 182 CREATE SEQUENCE file start 1;
 
 184 -- null table so it won't error
 
 185 -- deliberately no drop - importing the table is expensive and static, if it is already there better to avoid removing it
 
 186 CREATE TABLE wikipedia_article (
 
 187     language text NOT NULL,
 
 192     lat double precision,
 
 193     lon double precision,
 
 194     importance double precision,
 
 195     osm_type character(1),
 
 198 ALTER TABLE ONLY wikipedia_article ADD CONSTRAINT wikipedia_article_pkey PRIMARY KEY (language, title);
 
 199 CREATE INDEX idx_wikipedia_article_osm_id ON wikipedia_article USING btree (osm_type, osm_id);
 
 201 CREATE TABLE wikipedia_redirect (
 
 206 ALTER TABLE ONLY wikipedia_redirect ADD CONSTRAINT wikipedia_redirect_pkey PRIMARY KEY (language, from_title);