1 drop table import_status;
2 CREATE TABLE import_status (
3 lastimportdate timestamp NOT NULL
5 GRANT SELECT ON import_status TO "www-data" ;
7 drop table import_osmosis_log;
8 CREATE TABLE import_osmosis_log (
16 --drop table IF EXISTS query_log;
17 CREATE TABLE query_log (
24 CREATE INDEX idx_query_log ON query_log USING BTREE (starttime);
25 GRANT INSERT ON query_log TO "www-data" ;
27 CREATE TABLE new_query_log (
39 CREATE INDEX idx_new_query_log_starttime ON new_query_log USING BTREE (starttime);
40 GRANT INSERT ON new_query_log TO "www-data" ;
41 GRANT UPDATE ON new_query_log TO "www-data" ;
42 GRANT SELECT ON new_query_log TO "www-data" ;
44 create view vw_search_query_log as SELECT substr(query, 1, 50) AS query, starttime, endtime - starttime AS duration, substr(useragent, 1, 20) as
45 useragent, language, results, ipaddress FROM new_query_log WHERE type = 'search' ORDER BY starttime DESC;
47 --drop table IF EXISTS report_log;
48 CREATE TABLE report_log (
55 GRANT INSERT ON report_log TO "www-data" ;
57 drop table IF EXISTS word;
65 country_code varchar(2),
66 search_name_count INTEGER,
69 SELECT AddGeometryColumn('word', 'location', 4326, 'GEOMETRY', 2);
70 CREATE INDEX idx_word_word_id on word USING BTREE (word_id);
71 CREATE INDEX idx_word_word_token on word USING BTREE (word_token);
72 CREATE INDEX idx_word_trigram ON word USING gin(word_trigram gin_trgm_ops);
73 GRANT SELECT ON word TO "www-data" ;
74 DROP SEQUENCE seq_word;
75 CREATE SEQUENCE seq_word start 1;
77 drop table IF EXISTS location_area CASCADE;
78 CREATE TABLE location_area (
81 country_code VARCHAR(2),
83 rank_search INTEGER NOT NULL,
84 rank_address INTEGER NOT NULL,
87 SELECT AddGeometryColumn('location_area', 'centroid', 4326, 'POINT', 2);
88 SELECT AddGeometryColumn('location_area', 'geometry', 4326, 'GEOMETRY', 2);
90 CREATE TABLE location_area_large () INHERITS (location_area);
91 CREATE TABLE location_area_roadnear () INHERITS (location_area);
92 CREATE TABLE location_area_roadfar () INHERITS (location_area);
94 drop table IF EXISTS location_property CASCADE;
95 CREATE TABLE location_property (
98 parent_place_id INTEGER,
102 SELECT AddGeometryColumn('location_property', 'centroid', 4326, 'POINT', 2);
103 CREATE TABLE location_property_tiger () INHERITS (location_property);
104 CREATE INDEX idx_location_property_tiger_place_id ON location_property_tiger USING BTREE (place_id);
105 CREATE INDEX idx_location_property_tiger_parent_place_id ON location_property_tiger USING BTREE (parent_place_id);
106 CREATE INDEX idx_location_property_tiger_housenumber_parent_place_id ON location_property_tiger USING BTREE (parent_place_id, housenumber);
108 drop table IF EXISTS search_name_blank CASCADE;
109 CREATE TABLE search_name_blank (
112 address_rank integer,
114 country_code varchar(2),
115 name_vector integer[],
116 nameaddress_vector integer[]
118 SELECT AddGeometryColumn('search_name_blank', 'centroid', 4326, 'GEOMETRY', 2);
120 drop table IF EXISTS search_name;
121 CREATE TABLE search_name () INHERITS (search_name_blank);
122 CREATE INDEX search_name_name_vector_idx ON search_name USING GIN (name_vector gin__int_ops);
123 CREATE INDEX searchnameplacesearch_search_nameaddress_vector_idx ON search_name USING GIN (nameaddress_vector gin__int_ops);
124 CREATE INDEX idx_search_name_centroid ON search_name USING GIST (centroid);
125 CREATE INDEX idx_search_name_place_id ON search_name USING BTREE (place_id);
127 drop table IF EXISTS place_addressline;
128 CREATE TABLE place_addressline (
130 address_place_id INTEGER,
134 cached_rank_address integer
136 CREATE INDEX idx_place_addressline_place_id on place_addressline USING BTREE (place_id);
137 CREATE INDEX idx_place_addressline_address_place_id on place_addressline USING BTREE (address_place_id);
139 drop table IF EXISTS place_boundingbox CASCADE;
140 CREATE TABLE place_boundingbox (
149 CREATE INDEX idx_place_boundingbox_place_id on place_boundingbox USING BTREE (place_id);
150 SELECT AddGeometryColumn('place_boundingbox', 'outline', 4326, 'GEOMETRY', 2);
151 CREATE INDEX idx_place_boundingbox_outline ON place_boundingbox USING GIST (outline);
152 GRANT SELECT on place_boundingbox to "www-data" ;
153 GRANT INSERT on place_boundingbox to "www-data" ;
155 drop table IF EXISTS reverse_cache;
156 CREATE TABLE reverse_cache (
157 latlonzoomid integer,
158 country_code varchar(2),
161 GRANT SELECT on reverse_cache to "www-data" ;
162 GRANT INSERT on reverse_cache to "www-data" ;
163 CREATE INDEX idx_reverse_cache_latlonzoomid ON reverse_cache USING BTREE (latlonzoomid);
166 CREATE TABLE country (
167 country_code varchar(2),
169 country_default_language_code varchar(2)
171 SELECT AddGeometryColumn('country', 'geometry', 4326, 'POLYGON', 2);
172 insert into country select iso3166::varchar(2), 'name:en'->cntry_name, null,
173 ST_Transform(geometryn(the_geom, generate_series(1, numgeometries(the_geom))), 4326) from worldboundaries;
174 CREATE INDEX idx_country_country_code ON country USING BTREE (country_code);
175 CREATE INDEX idx_country_geometry ON country USING GIST (geometry);
178 CREATE TABLE placex (
179 place_id INTEGER NOT NULL,
191 country_code varchar(2),
193 parent_place_id INTEGER,
194 linked_place_id INTEGER,
195 rank_address INTEGER,
197 indexed_status INTEGER,
198 indexed_date TIMESTAMP,
199 geometry_sector INTEGER
201 SELECT AddGeometryColumn('placex', 'geometry', 4326, 'GEOMETRY', 2);
202 CREATE UNIQUE INDEX idx_place_id ON placex USING BTREE (place_id);
203 CREATE INDEX idx_placex_osmid ON placex USING BTREE (osm_type, osm_id);
204 CREATE INDEX idx_placex_rank_search ON placex USING BTREE (rank_search);
205 CREATE INDEX idx_placex_rank_address ON placex USING BTREE (rank_address);
206 CREATE INDEX idx_placex_geometry ON placex USING GIST (geometry);
208 --CREATE INDEX idx_placex_indexed ON placex USING BTREE (indexed);
210 CREATE INDEX idx_placex_pending ON placex USING BTREE (rank_search) where indexed_status > 0;
211 CREATE INDEX idx_placex_pendingsector ON placex USING BTREE (rank_search,geometry_sector) where indexed_status > 0;
213 --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;
215 CREATE INDEX idx_placex_parent_place_id ON placex USING BTREE (parent_place_id) where parent_place_id IS NOT NULL;
216 CREATE INDEX idx_placex_interpolation ON placex USING BTREE (geometry_sector) where indexed_status > 0 and class='place' and type='houses';
218 CREATE INDEX idx_placex_sector ON placex USING BTREE (geometry_sector,rank_address,osm_type,osm_id);
219 CLUSTER placex USING idx_placex_sector;
221 DROP SEQUENCE seq_place;
222 CREATE SEQUENCE seq_place start 1;
223 GRANT SELECT on placex to "www-data" ;
224 GRANT UPDATE ON placex to "www-data" ;
225 GRANT SELECT ON search_name to "www-data" ;
226 GRANT DELETE on search_name to "www-data" ;
227 GRANT INSERT on search_name to "www-data" ;
228 GRANT SELECT on place_addressline to "www-data" ;
229 GRANT INSERT ON place_addressline to "www-data" ;
230 GRANT DELETE on place_addressline to "www-data" ;
231 GRANT SELECT ON seq_word to "www-data" ;
232 GRANT UPDATE ON seq_word to "www-data" ;
233 GRANT INSERT ON word to "www-data" ;
234 GRANT SELECT ON planet_osm_ways to "www-data" ;
235 GRANT SELECT ON planet_osm_rels to "www-data" ;
236 GRANT SELECT on location_area to "www-data" ;
237 GRANT SELECT on country to "www-data" ;
239 -- insert creates the location tagbles, creates location indexes if indexed == true
240 CREATE TRIGGER placex_before_insert BEFORE INSERT ON placex
241 FOR EACH ROW EXECUTE PROCEDURE placex_insert();
243 -- update insert creates the location tables
244 CREATE TRIGGER placex_before_update BEFORE UPDATE ON placex
245 FOR EACH ROW EXECUTE PROCEDURE placex_update();
247 -- diff update triggers
248 CREATE TRIGGER placex_before_delete AFTER DELETE ON placex
249 FOR EACH ROW EXECUTE PROCEDURE placex_delete();
250 CREATE TRIGGER place_before_delete BEFORE DELETE ON place
251 FOR EACH ROW EXECUTE PROCEDURE place_delete();
252 CREATE TRIGGER place_before_insert BEFORE INSERT ON place
253 FOR EACH ROW EXECUTE PROCEDURE place_insert();
255 alter table placex add column geometry_sector INTEGER;
256 alter table placex add column indexed_status INTEGER;
257 alter table placex add column indexed_date TIMESTAMP;
259 update placex set geometry_sector = geometry_sector(geometry);
260 drop index idx_placex_pendingbylatlon;
261 drop index idx_placex_interpolation;
262 drop index idx_placex_sector;
263 CREATE INDEX idx_placex_pendingbylatlon ON placex USING BTREE (geometry_index(geometry_sector,indexed,name),rank_search)
264 where geometry_index(geometry_sector,indexed,name) IS NOT NULL;
265 CREATE INDEX idx_placex_interpolation ON placex USING BTREE (geometry_sector) where indexed = false and class='place' and type='houses';
266 CREATE INDEX idx_placex_sector ON placex USING BTREE (geometry_sector,rank_address,osm_type,osm_id);
268 DROP SEQUENCE seq_postcodes;
269 CREATE SEQUENCE seq_postcodes start 1;