Add land use groups lookup, drop original land use

This commit is contained in:
Maciej Ziarkowski 2019-12-02 20:58:50 +00:00
parent 1dddf3a31e
commit 8bbe63fee7
2 changed files with 41 additions and 37 deletions

View File

@ -3,11 +3,14 @@
--Landuse is a table as #358 --Landuse is a table as #358
--Land use class, group and order will be stored in a new table --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_order CASCADE;
DROP TABLE IF EXISTS reference_tables.buildings_landuse_group CASCADE;
DROP TABLE IF EXISTS reference_tables.buildings_landuse_class CASCADE; DROP TABLE IF EXISTS reference_tables.buildings_landuse_class CASCADE;
-- Land use class or classes, array object, client constrained. -- Land use class or classes, array object, client constrained.
ALTER TABLE buildings DROP COLUMN IF EXISTS current_landuse_class; ALTER TABLE buildings DROP COLUMN IF EXISTS current_landuse_class;
ALTER TABLE buildings DROP COLUMN IF EXISTS current_landuse_group;
-- Land use order, singular. Client and db constrained. -- Land use order, singular. Client and db constrained.
ALTER TABLE buildings DROP COLUMN IF EXISTS current_landuse_order; ALTER TABLE buildings DROP COLUMN IF EXISTS current_landuse_order;

View File

@ -6,52 +6,53 @@
CREATE TABLE IF NOT EXISTS reference_tables.buildings_landuse_order AS CREATE TABLE IF NOT EXISTS reference_tables.buildings_landuse_order AS
SELECT a.landuse_id, SELECT a.landuse_id,
a.description, a.description
a."level",
a.parent_id,
a.parent_name
FROM reference_tables.landuse_classifications a FROM reference_tables.landuse_classifications a
WHERE a."level" = 'order' WHERE a.level = 'order'
AND a.is_used IS TRUE ; AND a.is_used;
ALTER TABLE reference_tables.buildings_landuse_order
ADD UNIQUE (description);
CREATE TABLE IF NOT EXISTS reference_tables.buildings_landuse_group AS
SELECT a.landuse_id,
a.description,
a.parent_id AS parent_order_id
FROM reference_tables.landuse_classifications a
WHERE a.level = 'group'
AND a.is_used;
ALTER TABLE reference_tables.buildings_landuse_group
ADD UNIQUE (description);
--the below is for front end reference, not current used as a constraint --the below is for front end reference, not current used as a constraint
CREATE TABLE IF NOT EXISTS reference_tables.buildings_landuse_class AS CREATE TABLE IF NOT EXISTS reference_tables.buildings_landuse_class AS
SELECT a.landuse_id, SELECT a.landuse_id,
a.description, a.description,
a."level", a.parent_id AS parent_group_id
a.parent_id, FROM reference_tables.landuse_classifications a
a.parent_name WHERE a.level = 'class'
FROM reference_tables.landuse_classifications a AND a.is_used;
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) --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) --Interface will collected most detailed (class) but visualise highest level (order)
--Landuse is a table as #358 --Landuse is a table as #358
--Prerequisite run bulk_sources migration first --Prerequisite run bulk_sources migration first
-- Land use is table with 3 levels of hierachy (highest to lowest). order > group > class -- Land use is table with 3 levels of hierachy (highest to lowest). order > group > class
-- Land use order, singular. Client and db constrained with foreign key
ALTER TABLE buildings
ADD COLUMN IF NOT EXISTS current_landuse_order text,
ADD FOREIGN KEY (current_landuse_order)
REFERENCES reference_tables.buildings_landuse_order (description);
-- Land use groups, array. Derived from classes.
ALTER TABLE buildings ADD COLUMN IF NOT EXISTS current_landuse_group text ARRAY[41];
-- 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 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]; 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
--===========================================
--
-- We also collect original landuse, structure & process is as current land use
-- We don't currently collect intermediate historic uses
--
--===========================================
-- 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, ADD CONSTRAINT fk_original_landuse_order
FOREIGN KEY (original_landuse_order) REFERENCES reference_tables.buildings_landuse_order (description);