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 CREATE TABLE location_property_aux () INHERITS (location_property);
79 CREATE INDEX idx_location_property_aux_place_id ON location_property_aux USING BTREE (place_id);
80 CREATE INDEX idx_location_property_aux_parent_place_id ON location_property_aux USING BTREE (parent_place_id);
81 CREATE INDEX idx_location_property_aux_housenumber_parent_place_id ON location_property_aux USING BTREE (parent_place_id, housenumber);
82 GRANT SELECT ON location_property_aux TO "{www-user}";
84 CREATE TABLE location_property_tiger (linegeo GEOMETRY, place_id BIGINT, partition INTEGER, parent_place_id BIGINT, startnumber INTEGER, endnumber INTEGER, interpolationtype TEXT, postcode TEXT);
85 GRANT SELECT ON location_property_tiger TO "{www-user}";
87 CREATE TABLE location_property_osmline (
89 place_id BIGINT NOT NULL,
92 parent_place_id BIGINT,
95 interpolationtype TEXT,
99 calculated_country_code VARCHAR(2),
100 geometry_sector INTEGER,
101 indexed_status INTEGER,
102 indexed_date TIMESTAMP);
103 CREATE UNIQUE INDEX idx_osmline_place_id ON location_property_osmline (place_id) {ts:search-index};
104 CREATE INDEX idx_osmline_parent_place_id ON location_property_osmline (parent_place_id) {ts:search-index};
105 GRANT SELECT ON location_property_osmline TO "{www-user}";
107 drop table IF EXISTS search_name;
108 CREATE TABLE search_name (
111 address_rank integer,
113 country_code varchar(2),
114 name_vector integer[],
115 nameaddress_vector integer[]
117 SELECT AddGeometryColumn('search_name', 'centroid', 4326, 'GEOMETRY', 2);
118 CREATE INDEX idx_search_name_place_id ON search_name USING BTREE (place_id) {ts:search-index};
120 drop table IF EXISTS place_addressline;
121 CREATE TABLE place_addressline (
123 address_place_id BIGINT,
127 cached_rank_address integer
129 CREATE INDEX idx_place_addressline_place_id on place_addressline USING BTREE (place_id) {ts:search-index};
131 drop table if exists placex;
132 CREATE TABLE placex (
133 place_id BIGINT NOT NULL,
135 LIKE place INCLUDING CONSTRAINTS,
136 parent_place_id BIGINT,
137 linked_place_id BIGINT,
138 rank_address INTEGER,
141 indexed_status INTEGER,
142 indexed_date TIMESTAMP,
143 wikipedia TEXT, -- calculated wikipedia article name (language:title)
144 geometry_sector INTEGER,
145 calculated_country_code varchar(2)
147 SELECT AddGeometryColumn('placex', 'centroid', 4326, 'GEOMETRY', 2);
148 CREATE UNIQUE INDEX idx_place_id ON placex USING BTREE (place_id) {ts:search-index};
149 CREATE INDEX idx_placex_osmid ON placex USING BTREE (osm_type, osm_id) {ts:search-index};
150 CREATE INDEX idx_placex_linked_place_id ON placex USING BTREE (linked_place_id) {ts:address-index};
151 CREATE INDEX idx_placex_rank_search ON placex USING BTREE (rank_search, geometry_sector) {ts:address-index};
152 CREATE INDEX idx_placex_geometry ON placex USING GIST (geometry) {ts:search-index};
153 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;
155 DROP SEQUENCE IF EXISTS seq_place;
156 CREATE SEQUENCE seq_place start 1;
157 GRANT SELECT on placex to "{www-user}" ;
158 GRANT SELECT ON search_name to "{www-user}" ;
159 GRANT SELECT on place_addressline to "{www-user}" ;
160 GRANT SELECT ON seq_word to "{www-user}" ;
161 GRANT SELECT ON planet_osm_ways to "{www-user}" ;
162 GRANT SELECT ON planet_osm_rels to "{www-user}" ;
163 GRANT SELECT on location_area to "{www-user}" ;
165 -- insert creates the location tables, creates location indexes if indexed == true
166 CREATE TRIGGER placex_before_insert BEFORE INSERT ON placex
167 FOR EACH ROW EXECUTE PROCEDURE placex_insert();
169 -- update insert creates the location tables
170 CREATE TRIGGER placex_before_update BEFORE UPDATE ON placex
171 FOR EACH ROW EXECUTE PROCEDURE placex_update();
172 CREATE TRIGGER osmline_before_update BEFORE UPDATE ON location_property_osmline
173 FOR EACH ROW EXECUTE PROCEDURE osmline_update();
175 -- diff update triggers
176 CREATE TRIGGER placex_before_delete AFTER DELETE ON placex
177 FOR EACH ROW EXECUTE PROCEDURE placex_delete();
178 CREATE TRIGGER place_before_delete BEFORE DELETE ON place
179 FOR EACH ROW EXECUTE PROCEDURE place_delete();
180 CREATE TRIGGER place_before_insert BEFORE INSERT ON place
181 FOR EACH ROW EXECUTE PROCEDURE place_insert();
183 DROP SEQUENCE seq_postcodes;
184 CREATE SEQUENCE seq_postcodes start 1;
186 drop table import_polygon_error;
187 CREATE TABLE import_polygon_error (
193 country_code varchar(2),
197 SELECT AddGeometryColumn('import_polygon_error', 'prevgeometry', 4326, 'GEOMETRY', 2);
198 SELECT AddGeometryColumn('import_polygon_error', 'newgeometry', 4326, 'GEOMETRY', 2);
199 CREATE INDEX idx_import_polygon_error_osmid ON import_polygon_error USING BTREE (osm_type, osm_id);
200 GRANT SELECT ON import_polygon_error TO "{www-user}";
202 drop table import_polygon_delete;
203 CREATE TABLE import_polygon_delete (
209 CREATE INDEX idx_import_polygon_delete_osmid ON import_polygon_delete USING BTREE (osm_type, osm_id);
210 GRANT SELECT ON import_polygon_delete TO "{www-user}";
213 CREATE SEQUENCE file start 1;
215 -- null table so it won't error
216 -- deliberately no drop - importing the table is expensive and static, if it is already there better to avoid removing it
217 CREATE TABLE wikipedia_article (
218 language text NOT NULL,
223 lat double precision,
224 lon double precision,
225 importance double precision,
226 osm_type character(1),
229 ALTER TABLE ONLY wikipedia_article ADD CONSTRAINT wikipedia_article_pkey PRIMARY KEY (language, title);
230 CREATE INDEX idx_wikipedia_article_osm_id ON wikipedia_article USING btree (osm_type, osm_id);
232 CREATE TABLE wikipedia_redirect (
237 ALTER TABLE ONLY wikipedia_redirect ADD CONSTRAINT wikipedia_redirect_pkey PRIMARY KEY (language, from_title);