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 drop table if exists import_npi_log;
17 CREATE TABLE import_npi_log (
26 --drop table IF EXISTS query_log;
27 CREATE TABLE query_log (
34 CREATE INDEX idx_query_log ON query_log USING BTREE (starttime);
35 GRANT SELECT ON query_log TO "{www-user}" ;
36 GRANT INSERT ON query_log TO "{www-user}" ;
37 GRANT UPDATE ON query_log TO "{www-user}" ;
39 CREATE TABLE new_query_log (
51 CREATE INDEX idx_new_query_log_starttime ON new_query_log USING BTREE (starttime);
52 GRANT INSERT ON new_query_log TO "{www-user}" ;
53 GRANT UPDATE ON new_query_log TO "{www-user}" ;
54 GRANT SELECT ON new_query_log TO "{www-user}" ;
56 GRANT SELECT ON TABLE country_name TO "{www-user}";
57 GRANT SELECT ON TABLE gb_postcode TO "{www-user}";
59 create view vw_search_query_log as SELECT substr(query, 1, 50) AS query, starttime, endtime - starttime AS duration, substr(useragent, 1, 20) as
60 useragent, language, results, ipaddress FROM new_query_log WHERE type = 'search' ORDER BY starttime DESC;
62 drop table IF EXISTS word;
69 country_code varchar(2),
70 search_name_count INTEGER,
73 CREATE INDEX idx_word_word_token on word USING BTREE (word_token) {ts:search-index};
74 GRANT SELECT ON word TO "{www-user}" ;
75 DROP SEQUENCE IF EXISTS seq_word;
76 CREATE SEQUENCE seq_word start 1;
78 drop table IF EXISTS location_area CASCADE;
79 CREATE TABLE location_area (
82 country_code VARCHAR(2),
84 rank_search INTEGER NOT NULL,
85 rank_address INTEGER NOT NULL,
88 SELECT AddGeometryColumn('location_area', 'centroid', 4326, 'POINT', 2);
89 SELECT AddGeometryColumn('location_area', 'geometry', 4326, 'GEOMETRY', 2);
91 CREATE TABLE location_area_large () INHERITS (location_area);
93 drop table IF EXISTS location_property CASCADE;
94 CREATE TABLE location_property (
97 parent_place_id BIGINT,
101 SELECT AddGeometryColumn('location_property', 'centroid', 4326, 'POINT', 2);
103 drop table IF EXISTS search_name;
104 CREATE TABLE search_name (
107 address_rank integer,
109 country_code varchar(2),
110 name_vector integer[],
111 nameaddress_vector integer[]
113 SELECT AddGeometryColumn('search_name', 'centroid', 4326, 'GEOMETRY', 2);
114 CREATE INDEX idx_search_name_place_id ON search_name USING BTREE (place_id) {ts:search-index};
116 drop table IF EXISTS place_addressline;
117 CREATE TABLE place_addressline (
119 address_place_id BIGINT,
123 cached_rank_address integer
125 CREATE INDEX idx_place_addressline_place_id on place_addressline USING BTREE (place_id) {ts:search-index};
127 drop table if exists placex;
128 CREATE TABLE placex (
129 place_id BIGINT NOT NULL,
131 LIKE place INCLUDING CONSTRAINTS,
132 parent_place_id BIGINT,
133 linked_place_id BIGINT,
134 rank_address INTEGER,
137 indexed_status INTEGER,
138 indexed_date TIMESTAMP,
139 wikipedia TEXT, -- calculated wikipedia article name (language:title)
140 geometry_sector INTEGER,
141 calculated_country_code varchar(2)
143 SELECT AddGeometryColumn('placex', 'centroid', 4326, 'GEOMETRY', 2);
144 CREATE UNIQUE INDEX idx_place_id ON placex USING BTREE (place_id) {ts:search-index};
145 CREATE INDEX idx_placex_osmid ON placex USING BTREE (osm_type, osm_id) {ts:search-index};
146 CREATE INDEX idx_placex_linked_place_id ON placex USING BTREE (linked_place_id) {ts:address-index};
147 CREATE INDEX idx_placex_rank_search ON placex USING BTREE (rank_search, geometry_sector) {ts:address-index};
148 CREATE INDEX idx_placex_geometry ON placex USING GIST (geometry) {ts:search-index};
149 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;
151 DROP SEQUENCE IF EXISTS seq_place;
152 CREATE SEQUENCE seq_place start 1;
153 GRANT SELECT on placex to "{www-user}" ;
154 GRANT SELECT ON search_name to "{www-user}" ;
155 GRANT SELECT on place_addressline to "{www-user}" ;
156 GRANT SELECT ON seq_word to "{www-user}" ;
157 GRANT SELECT ON planet_osm_ways to "{www-user}" ;
158 GRANT SELECT ON planet_osm_rels to "{www-user}" ;
159 GRANT SELECT on location_area to "{www-user}" ;
161 -- insert creates the location tagbles, creates location indexes if indexed == true
162 CREATE TRIGGER placex_before_insert BEFORE INSERT ON placex
163 FOR EACH ROW EXECUTE PROCEDURE placex_insert();
165 -- update insert creates the location tables
166 CREATE TRIGGER placex_before_update BEFORE UPDATE ON placex
167 FOR EACH ROW EXECUTE PROCEDURE placex_update();
169 -- diff update triggers
170 CREATE TRIGGER placex_before_delete AFTER DELETE ON placex
171 FOR EACH ROW EXECUTE PROCEDURE placex_delete();
172 CREATE TRIGGER place_before_delete BEFORE DELETE ON place
173 FOR EACH ROW EXECUTE PROCEDURE place_delete();
174 CREATE TRIGGER place_before_insert BEFORE INSERT ON place
175 FOR EACH ROW EXECUTE PROCEDURE place_insert();
177 DROP SEQUENCE seq_postcodes;
178 CREATE SEQUENCE seq_postcodes start 1;
180 drop table import_polygon_error;
181 CREATE TABLE import_polygon_error (
187 country_code varchar(2),
191 SELECT AddGeometryColumn('import_polygon_error', 'prevgeometry', 4326, 'GEOMETRY', 2);
192 SELECT AddGeometryColumn('import_polygon_error', 'newgeometry', 4326, 'GEOMETRY', 2);
193 CREATE INDEX idx_import_polygon_error_osmid ON import_polygon_error USING BTREE (osm_type, osm_id);
194 GRANT SELECT ON import_polygon_error TO "{www-user}";
196 drop table import_polygon_delete;
197 CREATE TABLE import_polygon_delete (
203 CREATE INDEX idx_import_polygon_delete_osmid ON import_polygon_delete USING BTREE (osm_type, osm_id);
204 GRANT SELECT ON import_polygon_delete TO "{www-user}";
207 CREATE SEQUENCE file start 1;
209 -- null table so it won't error
210 -- deliberately no drop - importing the table is expensive and static, if it is already there better to avoid removing it
211 CREATE TABLE wikipedia_article (
212 language text NOT NULL,
217 lat double precision,
218 lon double precision,
219 importance double precision,
220 osm_type character(1),
223 ALTER TABLE ONLY wikipedia_article ADD CONSTRAINT wikipedia_article_pkey PRIMARY KEY (language, title);
224 CREATE INDEX idx_wikipedia_article_osm_id ON wikipedia_article USING btree (osm_type, osm_id);
226 CREATE TABLE wikipedia_redirect (
231 ALTER TABLE ONLY wikipedia_redirect ADD CONSTRAINT wikipedia_redirect_pkey PRIMARY KEY (language, from_title);