-- This document was automatically created by the ADE-Manager tool of 3DCityDB (https://www.3dcitydb.org) on 2021-01-10 14:57:11 
-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
-- *********************************** Create tables ************************************** 
-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
-- -------------------------------------------------------------------- 
-- FWES_energysurvey 
-- -------------------------------------------------------------------- 
CREATE TABLE FWES_energysurvey
(
    id INTEGER NOT NULL,
    biomasselectricitypotential NUMERIC,
    biomasselectricitypotentialu VARCHAR(1000),
    biomassprimaryenergypotent_1 VARCHAR(1000),
    biomassprimaryenergypotentia NUMERIC,
    biomassthermalpotential NUMERIC,
    biomassthermalpotentialunit VARCHAR(1000),
    electricitypotentialfrompv_1 VARCHAR(1000),
    electricitypotentialfrompvbu NUMERIC,
    residentialelectricitydema_1 VARCHAR(1000),
    residentialelectricitydemand NUMERIC,
    spacecoolingdemand NUMERIC,
    spacecoolingdemandunit VARCHAR(1000),
    spaceheatingdemand NUMERIC,
    spaceheatingdemandunit VARCHAR(1000),
    systemsurvey_energysurvey_id INTEGER,
    PRIMARY KEY (id)
);

-- -------------------------------------------------------------------- 
-- FWES_foodsurvey 
-- -------------------------------------------------------------------- 
CREATE TABLE FWES_foodsurvey
(
    id INTEGER NOT NULL,
    foodcategory VARCHAR(1000),
    foodcategory_codespace VARCHAR(1000),
    foodconsumption NUMERIC,
    foodconsumptionunit VARCHAR(1000),
    fooddemand NUMERIC,
    fooddemandunit VARCHAR(1000),
    foodimport NUMERIC,
    foodimportunit VARCHAR(1000),
    foodproduction NUMERIC,
    foodproductionenergydemand NUMERIC,
    foodproductionenergydemandun VARCHAR(1000),
    foodproductionunit VARCHAR(1000),
    foodproductionwaterdemand NUMERIC,
    foodproductionwaterdemanduni VARCHAR(1000),
    systemsurvey_foodsurvey_id INTEGER,
    PRIMARY KEY (id)
);

-- -------------------------------------------------------------------- 
-- FWES_fwesystem 
-- -------------------------------------------------------------------- 
CREATE TABLE FWES_fwesystem
(
    id INTEGER NOT NULL,
    fwesystemname VARCHAR(1000),
    lod0multisurface_id INTEGER,
    PRIMARY KEY (id)
);

-- -------------------------------------------------------------------- 
-- FWES_systemsurvey 
-- -------------------------------------------------------------------- 
CREATE TABLE FWES_systemsurvey
(
    id INTEGER NOT NULL,
    buildingfootprintarea NUMERIC,
    buildingfootprintarea_uom VARCHAR(1000),
    fwesystem_consistsoffwesu_id INTEGER,
    objectclass_id INTEGER,
    openplotarea NUMERIC,
    openplotarea_uom VARCHAR(1000),
    population INTEGER,
    settlementarea NUMERIC,
    settlementarea_uom VARCHAR(1000),
    surfacearea NUMERIC,
    surfacearea_uom VARCHAR(1000),
    surveydescription VARCHAR(1000),
    surveyyear INTEGER,
    surveyyearversion NUMERIC,
    trafficarea NUMERIC,
    trafficarea_uom VARCHAR(1000),
    vegetationarea NUMERIC,
    vegetationarea_uom VARCHAR(1000),
    waterbodyarea NUMERIC,
    waterbodyarea_uom VARCHAR(1000),
    PRIMARY KEY (id)
);

-- -------------------------------------------------------------------- 
-- FWES_watersurvey 
-- -------------------------------------------------------------------- 
CREATE TABLE FWES_watersurvey
(
    id INTEGER NOT NULL,
    domestichotwaterdemand NUMERIC,
    domestichotwaterdemandunit VARCHAR(1000),
    domesticsolidwaste NUMERIC,
    domesticsolidwasteunit VARCHAR(1000),
    domesticwaterdemand NUMERIC,
    domesticwaterdemandunit VARCHAR(1000),
    domesticwaterwaste NUMERIC,
    domesticwaterwasteunit VARCHAR(1000),
    systemsurvey_watersurvey_id INTEGER,
    totaldomesticwaste NUMERIC,
    totaldomesticwasteenergypo_1 VARCHAR(1000),
    totaldomesticwasteenergypote NUMERIC,
    totaldomesticwasteunit VARCHAR(1000),
    PRIMARY KEY (id)
);

-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
-- *********************************** Create foreign keys ******************************** 
-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
-- -------------------------------------------------------------------- 
-- FWES_energysurvey 
-- -------------------------------------------------------------------- 
ALTER TABLE FWES_energysurvey ADD CONSTRAINT FWES_energysurvey_fk FOREIGN KEY (id)
REFERENCES FWES_systemsurvey (id);

ALTER TABLE FWES_energysurvey ADD CONSTRAINT FWES_energy_syste_energ_fk FOREIGN KEY (systemsurvey_energysurvey_id)
REFERENCES FWES_systemsurvey (id);

-- -------------------------------------------------------------------- 
-- FWES_foodsurvey 
-- -------------------------------------------------------------------- 
ALTER TABLE FWES_foodsurvey ADD CONSTRAINT FWES_foodsurvey_fk FOREIGN KEY (id)
REFERENCES FWES_systemsurvey (id);

ALTER TABLE FWES_foodsurvey ADD CONSTRAINT FWES_foodsu_syste_foods_fk FOREIGN KEY (systemsurvey_foodsurvey_id)
REFERENCES FWES_systemsurvey (id);

-- -------------------------------------------------------------------- 
-- FWES_fwesystem 
-- -------------------------------------------------------------------- 
ALTER TABLE FWES_fwesystem ADD CONSTRAINT FWES_fwesystem_fk FOREIGN KEY (id)
REFERENCES cityobject (id);

ALTER TABLE FWES_fwesystem ADD CONSTRAINT FWES_fwesystem_lod0mult_fk FOREIGN KEY (lod0multisurface_id)
REFERENCES surface_geometry (id);

-- -------------------------------------------------------------------- 
-- FWES_systemsurvey 
-- -------------------------------------------------------------------- 
ALTER TABLE FWES_systemsurvey ADD CONSTRAINT FWES_systemsurvey_fk FOREIGN KEY (id)
REFERENCES cityobject (id);

ALTER TABLE FWES_systemsurvey ADD CONSTRAINT FWES_systemsur_objectcl_fk FOREIGN KEY (objectclass_id)
REFERENCES objectclass (id);

ALTER TABLE FWES_systemsurvey ADD CONSTRAINT FWES_system_fwesy_consi_fk FOREIGN KEY (fwesystem_consistsoffwesu_id)
REFERENCES FWES_fwesystem (id);

-- -------------------------------------------------------------------- 
-- FWES_watersurvey 
-- -------------------------------------------------------------------- 
ALTER TABLE FWES_watersurvey ADD CONSTRAINT FWES_watersurvey_fk FOREIGN KEY (id)
REFERENCES FWES_systemsurvey (id);

ALTER TABLE FWES_watersurvey ADD CONSTRAINT FWES_waters_syste_water_fk FOREIGN KEY (systemsurvey_watersurvey_id)
REFERENCES FWES_systemsurvey (id);

-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
-- *********************************** Create Indexes ************************************* 
-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
-- -------------------------------------------------------------------- 
-- FWES_energysurvey 
-- -------------------------------------------------------------------- 
CREATE INDEX FWES_energ_syste_energ_fkx ON FWES_energysurvey
    USING btree
    (
      systemsurvey_energysurvey_id ASC NULLS LAST
    )   WITH (FILLFACTOR = 90);

-- -------------------------------------------------------------------- 
-- FWES_foodsurvey 
-- -------------------------------------------------------------------- 
CREATE INDEX FWES_foods_syste_foods_fkx ON FWES_foodsurvey
    USING btree
    (
      systemsurvey_foodsurvey_id ASC NULLS LAST
    )   WITH (FILLFACTOR = 90);

-- -------------------------------------------------------------------- 
-- FWES_fwesystem 
-- -------------------------------------------------------------------- 
CREATE INDEX FWES_fwesyste_lod0mult_fkx ON FWES_fwesystem
    USING btree
    (
      lod0multisurface_id ASC NULLS LAST
    )   WITH (FILLFACTOR = 90);

-- -------------------------------------------------------------------- 
-- FWES_systemsurvey 
-- -------------------------------------------------------------------- 
CREATE INDEX FWES_syste_fwesy_consi_fkx ON FWES_systemsurvey
    USING btree
    (
      fwesystem_consistsoffwesu_id ASC NULLS LAST
    )   WITH (FILLFACTOR = 90);

CREATE INDEX FWES_systemsu_objectcl_fkx ON FWES_systemsurvey
    USING btree
    (
      objectclass_id ASC NULLS LAST
    )   WITH (FILLFACTOR = 90);

-- -------------------------------------------------------------------- 
-- FWES_watersurvey 
-- -------------------------------------------------------------------- 
CREATE INDEX FWES_water_syste_water_fkx ON FWES_watersurvey
    USING btree
    (
      systemsurvey_watersurvey_id ASC NULLS LAST
    )   WITH (FILLFACTOR = 90);

-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
-- *********************************** Create Sequences *********************************** 
-- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
