Add location, date, size, likes to database
This commit is contained in:
parent
36ee3e8c23
commit
d1ea702939
37
migrations/004.location-date-size-like.down.sql
Normal file
37
migrations/004.location-date-size-like.down.sql
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
-- Drop location fields
|
||||||
|
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS location_name;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS location_number;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS location_street;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS location_line_two;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS location_town;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS location_postcode;
|
||||||
|
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS location_latitude;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS location_longitude;
|
||||||
|
|
||||||
|
-- Drop date fields
|
||||||
|
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS date_year;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS date_lower;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS date_upper;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS date_source;
|
||||||
|
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS facade_year;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS facade_upper;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS facade_lower;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS facade_source;
|
||||||
|
|
||||||
|
-- Drop size fields
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS size_storeys_attic;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS size_storeys_core;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS size_storeys_basement;
|
||||||
|
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS size_height_apex;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS size_floor_area_ground;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS size_floor_area_total;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS size_width_frontage;
|
||||||
|
|
||||||
|
-- Drop like-me fields
|
||||||
|
DROP TABLE IF EXISTS building_user_likes;
|
||||||
|
ALTER TABLE buildings DROP COLUMN IF EXISTS likes_total;
|
78
migrations/004.location-date-size-like.up.sql
Normal file
78
migrations/004.location-date-size-like.up.sql
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
-- Location fields
|
||||||
|
|
||||||
|
-- Building Name
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS location_name varchar;
|
||||||
|
ALTER TABLE buildings ADD CONSTRAINT buildings_location_name_len CHECK (length(location_name) < 90);
|
||||||
|
-- Building Number
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS location_number varchar;
|
||||||
|
ALTER TABLE buildings ADD CONSTRAINT buildings_location_number_len CHECK (length(location_number) < 10);
|
||||||
|
-- Street
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS location_street varchar;
|
||||||
|
ALTER TABLE buildings ADD CONSTRAINT buildings_location_street_len CHECK (length(location_street) < 90);
|
||||||
|
-- Address line 2
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS location_line_two varchar;
|
||||||
|
ALTER TABLE buildings ADD CONSTRAINT buildings_location_line_two_len CHECK (length(location_line_two) < 90);
|
||||||
|
-- Town
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS location_town varchar;
|
||||||
|
ALTER TABLE buildings ADD CONSTRAINT buildings_location_town_len CHECK (length(location_town) < 90);
|
||||||
|
-- Postcode
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS location_postcode varchar;
|
||||||
|
ALTER TABLE buildings ADD CONSTRAINT buildings_location_postcode_len CHECK (length(location_postcode) < 11);
|
||||||
|
|
||||||
|
-- Explicit coordinates (user-provided; see geometries table for polygons)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS location_latitude double precision;
|
||||||
|
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS location_longitude double precision;
|
||||||
|
|
||||||
|
|
||||||
|
-- Building age (main construction, facade)
|
||||||
|
|
||||||
|
-- Year built (best estimate)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS date_year smallint;
|
||||||
|
-- Year built (lower estimate)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS date_lower smallint;
|
||||||
|
-- Year built (upper estimate)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS date_upper smallint;
|
||||||
|
-- Date Source
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS date_source varchar;
|
||||||
|
ALTER TABLE buildings ADD CONSTRAINT buildings_date_source_len CHECK (length(date_source) < 150);
|
||||||
|
|
||||||
|
-- Facade date
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS facade_year smallint;
|
||||||
|
-- Facade date (upper)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS facade_upper smallint;
|
||||||
|
-- Facade date (lower)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS facade_lower smallint;
|
||||||
|
-- Date Source
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS facade_source varchar;
|
||||||
|
ALTER TABLE buildings ADD CONSTRAINT buildings_facade_source_len CHECK (length(facade_source) < 150);
|
||||||
|
|
||||||
|
|
||||||
|
-- Size
|
||||||
|
|
||||||
|
-- Attic storeys
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_storeys_attic smallint;
|
||||||
|
-- Core storeys
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_storeys_core smallint;
|
||||||
|
-- Basement storeys
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_storeys_basement smallint;
|
||||||
|
|
||||||
|
-- Height to apex (m)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_height_apex real;
|
||||||
|
-- Ground floor area (m2)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_floor_area_ground real;
|
||||||
|
-- Total floor area (m2)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_floor_area_total real;
|
||||||
|
-- Frontage Width (m)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS size_width_frontage real;
|
||||||
|
|
||||||
|
|
||||||
|
-- Likes
|
||||||
|
|
||||||
|
-- Total likes (denormalised from up-to-one-vote-per-user)
|
||||||
|
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS likes_total integer;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS building_user_likes (
|
||||||
|
building_id integer REFERENCES buildings,
|
||||||
|
user_id uuid REFERENCES users
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user