diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..93f99a4a Binary files /dev/null and b/.DS_Store differ diff --git a/migrations/.DS_Store b/migrations/.DS_Store new file mode 100644 index 00000000..5008ddfc Binary files /dev/null and b/migrations/.DS_Store differ diff --git a/migrations/0xx.landuse.down.sql b/migrations/0xx.landuse.down.sql index 90abcc34..c183bc13 100644 --- a/migrations/0xx.landuse.down.sql +++ b/migrations/0xx.landuse.down.sql @@ -1,9 +1,9 @@ --Landuse is hierachical. Highest level is Order (ie. Residential) then Group (ie Residential-Dwelling) then Class (ie Residential-Dwelling-Detached house) --Interface will collected most detailed (class) but visualise highest level (order) --Landuse is a table as #358 - --- Land use is table with 3 levels of hierachy (highest to lowest). order > group > class -DROP TABLE IF EXISTS landuse_classifications; +--Land use class, group and order will be stored in a new table +DROP TABLE IF EXISTS reference_tables.buildings_landuse_order CASCADE; +DROP TABLE IF EXISTS reference_tables.buildings_landuse_class CASCADE; -- Land use class or classes, array object, client constrained. ALTER TABLE buildings DROP COLUMN IF EXISTS current_landuse_class; @@ -11,8 +11,7 @@ ALTER TABLE buildings DROP COLUMN IF EXISTS current_landuse_class; -- Land use order, singular. Client and db constrained. ALTER TABLE buildings DROP COLUMN IF EXISTS current_landuse_order; ---Land use class, group and order will be stored in a new table -DROP TABLE IF EXISTS building_landuse CASCADE; + --=========================================== -- diff --git a/migrations/0xx.landuse.up.sql b/migrations/0xx.landuse.up.sql index a7f2f54b..9f3ae1ee 100644 --- a/migrations/0xx.landuse.up.sql +++ b/migrations/0xx.landuse.up.sql @@ -1,18 +1,43 @@ +-- Create land use and fields +--Landuse is hierachical. Highest level is Order (Residential) then Group (Residential-Dwelling) then Class (Residential-Dwelling-Detached house) +--Some ETL work required to get this together refer to analysis repo +--Prerequesite is to have first run bulk_data_sources migrations + --Then create table landuse_order for the app, this is used as foreign key for current and original landuse_order + +CREATE TABLE IF NOT EXISTS reference_tables.buildings_landuse_order AS +SELECT a.landuse_id, + a.description, + a."level", + a.parent_id, + a.parent_name +FROM reference_tables.landuse_classifications a +WHERE a."level" = 'order' + AND a.is_used IS TRUE ; + +--the below is for front end reference, not current used as a constraint + CREATE TABLE IF NOT EXISTS reference_tables.buildings_landuse_class AS + SELECT a.landuse_id, + a.description, + a."level", + a.parent_id, + a.parent_name + FROM reference_tables.landuse_classifications a + WHERE a."level" = 'class' + AND a.is_used IS TRUE ; + +ALTER TABLE buildings ADD COLUMN IF NOT EXISTS current_landuse_order text, ADD CONSTRAINT fk_current_landuse_order +FOREIGN KEY (current_landuse_order) REFERENCES reference_tables.buildings_landuse_order (description); + --Landuse is hierachical. Highest level is Order (Residential) then Group (Residential-Dwelling) then Class (Residential-Dwelling-Detached house) --Interface will collected most detailed (class) but visualise highest level (order) --Landuse is a table as #358 +--Prerequisite run bulk_sources migration first + -- Land use is table with 3 levels of hierachy (highest to lowest). order > group > class + -- Land use class or classes, array object, client constrained. ARRAY[] is used to constrain array size. The array is limited to 250 based on Westfield Stratford as a single toid with many uses, this may want to be reduced down to reduce maximum size. --- Land use is table with 3 levels of hierachy (highest to lowest). order > group > class - --- Land use class or classes, array object, client constrained. ARRAY[] is used to constrain array size. The array is limited to 250 based on Westfield Stratford as a single toid with many uses, this may want to be reduced down to reduce maximum size. ALTER TABLE buildings ADD COLUMN IF NOT EXISTS current_landuse_class text ARRAY[250]; -- Land use order, singular. Client and db constrained with foreign key --- -ALTER TABLE buildings ADD COLUMN IF NOT EXISTS current_landuse_order text, -ADD CONSTRAINT fk_landuse_order -FOREIGN KEY ("level") -REFERENCES bulk_sources.nlud_classification_order_group ("level"); @@ -22,9 +47,11 @@ REFERENCES bulk_sources.nlud_classification_order_group ("level"); -- We don't currently collect intermediate historic uses -- --=========================================== + -- Original Land use class or classes, array object, client constrained. --- Original Land use class or classes, array object, client constrained. ALTER TABLE buildings ADD COLUMN IF NOT EXISTS original_landuse_class text ARRAY[250]; -- Land use order, singular. Client and db constrained. -ALTER TABLE buildings ADD COLUMN IF NOT EXISTS original_landuse_order text; + +ALTER TABLE buildings ADD COLUMN IF NOT EXISTS original_landuse_order text, ADD CONSTRAINT fk_original_landuse_order +FOREIGN KEY (original_landuse_order) REFERENCES reference_tables.buildings_landuse_order (description);