
ingo@2805: SET AUTOCOMMIT ON;
ingo@2805: 
ingo@2805: CREATE SEQUENCE LOCATION_SYSTEM_SEQ;
ingo@2805: 
ingo@2805: CREATE TABLE location_system (
ingo@2805:     id          NUMBER(38,0) NOT NULL,
ingo@2805:     name        VARCHAR(32)  NOT NULL,
ingo@2805:     description VARCHAR(255),
ingo@2805:     PRIMARY KEY(id)
ingo@2805: );
ingo@2805: 
ingo@2805: 
ingo@2805: CREATE SEQUENCE ELEVATION_MODEL_SEQ;
ingo@2805: 
ingo@2805: CREATE TABLE elevation_model (
ingo@2805:     id          NUMBER(38,0) NOT NULL,
ingo@2805:     name        VARCHAR(32)  NOT NULL,
ingo@2805:     unit_id     NUMBER(38,0) NOT NULL,
ingo@2805:     PRIMARY KEY(id),
ingo@2805:     CONSTRAINT fk_unit FOREIGN KEY (unit_id) REFERENCES units(id)
ingo@2805: );
ingo@2805: 
ingo@2805: 
tom@5224: -- lookup table for bedheight types
ingo@2805: CREATE TABLE bed_height_type (
ingo@2805:     id          NUMBER(38,0) NOT NULL,
teichmann@5273:     name        VARCHAR(65)  NOT NULL,
ingo@2805:     PRIMARY KEY(id)
ingo@2805: );
tom@5275: INSERT INTO bed_height_type VALUES (1, 'Querprofile');
tom@5275: INSERT INTO bed_height_type VALUES (2, 'Flächenpeilung');
tom@5275: INSERT INTO bed_height_type VALUES (3, 'Flächen- u. Querprofilpeilungen');
tom@5275: INSERT INTO bed_height_type VALUES (4, 'DGM');
tom@5275: INSERT INTO bed_height_type VALUES (5, 'TIN');
tom@5275: INSERT INTO bed_height_type VALUES (6, 'Modell');
ingo@2805: 
ingo@2805: 
ingo@2805: CREATE SEQUENCE BED_HEIGHT_SINGLE_ID_SEQ;
ingo@2805: 
ingo@2805: CREATE TABLE bed_height_single (
ingo@2805:     id                      NUMBER(38,0) NOT NULL,
ingo@2809:     river_id                NUMBER(38,0) NOT NULL,
tom@5448:     year                    NUMBER(38,0),
tom@5448:     sounding_width          NUMBER(38,0),
ingo@2805:     type_id                 NUMBER(38,0) NOT NULL,
ingo@2807:     location_system_id      NUMBER(38,0) NOT NULL,
ingo@2805:     cur_elevation_model_id  NUMBER(38,0) NOT NULL,
ingo@2805:     old_elevation_model_id  NUMBER(38,0),
tom@5448:     range_id                NUMBER(38,0),
ingo@2805:     evaluation_by           VARCHAR(255),
ingo@2805:     description             VARCHAR(255),
ingo@2805:     PRIMARY KEY(id),
ingo@2809:     CONSTRAINT fk_bed_single_river_id FOREIGN KEY (river_id) REFERENCES rivers(id),
ingo@2805:     CONSTRAINT fk_type FOREIGN KEY (type_id) REFERENCES bed_height_type(id),
ingo@2807:     CONSTRAINT fk_location_system FOREIGN KEY (location_system_id) REFERENCES location_system(id),
ingo@2805:     CONSTRAINT fk_cur_elevation_model FOREIGN KEY (cur_elevation_model_id) REFERENCES elevation_model(id),
ingo@2805:     CONSTRAINT fk_old_elevation_model FOREIGN KEY (old_elevation_model_id) REFERENCES elevation_model(id),
ingo@2805:     CONSTRAINT fk_range FOREIGN KEY (range_id) REFERENCES ranges(id)
ingo@2805: );
ingo@2805: 
ingo@2805: 
ingo@2805: CREATE SEQUENCE BED_HEIGHT_EPOCH_ID_SEQ;
ingo@2805: 
ingo@2805: CREATE TABLE bed_height_epoch (
ingo@2805:     id                      NUMBER(38,0) NOT NULL,
ingo@2810:     river_id                NUMBER(38,0) NOT NULL,
ingo@2805:     time_interval_id        NUMBER(38,0) NOT NULL,
ingo@2805:     -- sounding_with           NUMBER(38,0) NOT NULL,
ingo@2805:     -- type_id                 NUMBER(38,0) NOT NULL,
ingo@2805:     cur_elevation_model_id  NUMBER(38,0) NOT NULL,
ingo@2805:     old_elevation_model_id  NUMBER(38,0),
tom@5448:     range_id                NUMBER(38,0),
ingo@2805:     evaluation_by           VARCHAR(255),
ingo@2805:     description             VARCHAR(255),
ingo@2805:     PRIMARY KEY(id),
ingo@2805:     CONSTRAINT fk_time_interval FOREIGN KEY (time_interval_id) REFERENCES time_intervals(id),
ingo@2805:     CONSTRAINT fk_epoch_cur_elevation_model FOREIGN KEY (cur_elevation_model_id) REFERENCES elevation_model(id),
ingo@2805:     CONSTRAINT fk_epoch_old_elevation_model FOREIGN KEY (old_elevation_model_id) REFERENCES elevation_model(id),
ingo@2805:     CONSTRAINT fk_epoch_range FOREIGN KEY (range_id) REFERENCES ranges(id)
ingo@2805: );
ingo@2805: 
ingo@2805: 
ingo@2805: CREATE SEQUENCE BED_SINGLE_VALUES_ID_SEQ;
ingo@2805: 
ingo@2805: CREATE TABLE bed_height_single_values (
ingo@2805:     id                      NUMBER(38,0) NOT NULL,
ingo@2805:     bed_height_single_id    NUMBER(38,0) NOT NULL,
ingo@2805:     station                 NUMBER(38,2) NOT NULL,
ingo@2805:     height                  NUMBER(38,2),
ingo@2805:     uncertainty             NUMBER(38,2),
felix@3953:     data_gap                NUMBER(38,2),
felix@3953:     sounding_width          NUMBER(38,2),
felix@3953:     width                   NUMBER(38,2),
ingo@2805:     PRIMARY KEY(id),
ingo@2805:     CONSTRAINT fk_bed_single_values_parent FOREIGN KEY (bed_height_single_id) REFERENCES bed_height_single(id)
ingo@2805: );
ingo@2805: 
ingo@2805: 
ingo@2805: CREATE SEQUENCE BED_EPOCH_VALUES_ID_SEQ;
ingo@2805: 
ingo@2805: CREATE TABLE bed_height_epoch_values (
ingo@2805:     id                      NUMBER(38,0) NOT NULL,
ingo@2805:     bed_height_epoch_id     NUMBER(38,0) NOT NULL,
ingo@2805:     station                 NUMBER(38,2) NOT NULL,
ingo@2805:     height                  NUMBER(38,2),
ingo@2805:     PRIMARY KEY(id),
ingo@2805:     CONSTRAINT fk_bed_epoch_values_parent FOREIGN KEY (bed_height_epoch_id) REFERENCES bed_height_epoch(id)
ingo@2805: );
ingo@2805: 
ingo@2812: 
ingo@2812: CREATE SEQUENCE DEPTHS_ID_SEQ;
ingo@2812: 
ingo@2812: CREATE TABLE depths (
ingo@2812:     id      NUMBER(38,0) NOT NULL,
ingo@2812:     lower   NUMBER(38,2) NOT NULL,
ingo@2812:     upper   NUMBER(38,2) NOT NULL,
tom@5441:     PRIMARY KEY(id)
ingo@2812: );
ingo@2812: 
ingo@2812: 
ingo@2812: CREATE SEQUENCE SEDIMENT_DENSITY_ID_SEQ;
ingo@2812: 
ingo@2812: CREATE TABLE sediment_density (
ingo@2812:     id          NUMBER(38,0) NOT NULL,
ingo@2812:     river_id    NUMBER(38,0) NOT NULL,
ingo@2812:     depth_id    NUMBER(38,0) NOT NULL,
ingo@2817:     description VARCHAR(256),
ingo@2812:     PRIMARY KEY(id),
ingo@2812:     CONSTRAINT fk_sd_river_id FOREIGN KEY (river_id) REFERENCES rivers(id),
tom@5441:     CONSTRAINT fk_sd_depth_id FOREIGN KEY (depth_id) REFERENCES depths(id)
ingo@2812: );
ingo@2812: 
ingo@2812: 
ingo@2812: CREATE SEQUENCE SEDIMENT_DENSITY_VALUES_ID_SEQ;
ingo@2812: 
ingo@2812: CREATE TABLE sediment_density_values (
ingo@2812:     id                  NUMBER(38,0) NOT NULL,
ingo@2812:     sediment_density_id NUMBER(38,0) NOT NULL,
ingo@2816:     station             NUMBER(38,2) NOT NULL,
ingo@2812:     density             NUMBER(38,2) NOT NULL,
ingo@2812:     description         VARCHAR(256),
rrenkert@4523:     year                NUMBER(38,0),
ingo@2812:     PRIMARY KEY(id),
ingo@2816:     CONSTRAINT fk_sdv_sediment_density_id FOREIGN KEY(sediment_density_id) REFERENCES sediment_density(id)
ingo@2812: );
ingo@2818: 
ingo@2818: 
ingo@2818: CREATE SEQUENCE MORPHOLOGIC_WIDTH_ID_SEQ;
ingo@2818: 
ingo@2818: CREATE TABLE morphologic_width (
ingo@2818:     id          NUMBER(38,0) NOT NULL,
ingo@2818:     river_id    NUMBER(38,0) NOT NULL,
ingo@2818:     unit_id     NUMBER(38,0) NOT NULL,
ingo@2818:     PRIMARY KEY(id),
ingo@2818:     CONSTRAINT fk_mw_river_id FOREIGN KEY(river_id) REFERENCES rivers(id),
ingo@2818:     CONSTRAINT fk_mw_unit_id FOREIGN KEY(unit_id) REFERENCES units(id)
ingo@2818: );
ingo@2818: 
ingo@2818: 
ingo@2818: CREATE SEQUENCE MORPH_WIDTH_VALUES_ID_SEQ;
ingo@2818: 
ingo@2818: CREATE TABLE morphologic_width_values (
ingo@2818:     id                      NUMBER(38,0) NOT NULL,
ingo@2818:     morphologic_width_id    NUMBER(38,0) NOT NULL,
ingo@2818:     station                 NUMBER(38,3) NOT NULL,
ingo@2818:     width                   NUMBER(38,3) NOT NULL,
ingo@2819:     description             VARCHAR(256),
ingo@2818:     PRIMARY KEY(id),
ingo@2818:     CONSTRAINT fk_mwv_morphologic_width_id FOREIGN KEY (morphologic_width_id) REFERENCES morphologic_width(id)
ingo@2818: );
ingo@2824: 
ingo@2824: 
ingo@2824: CREATE SEQUENCE DISCHARGE_ZONE_ID_SEQ;
ingo@2824: 
ingo@2824: CREATE TABLE discharge_zone (
ingo@2824:     id                      NUMBER(38,0) NOT NULL,
ingo@2824:     river_id                NUMBER(38,0) NOT NULL,
ingo@2824:     gauge_name              VARCHAR(64)  NOT NULL, -- this is not very proper, but there are gauges with no db instance
ingo@2833:     value                   NUMBER(38,3) NOT NULL,
ingo@2833:     lower_discharge         VARCHAR(16)  NOT NULL,
ingo@2833:     upper_discharge         VARCHAR(16),
ingo@2824:     PRIMARY KEY(id),
ingo@2833:     CONSTRAINT fk_dz_river_id FOREIGN KEY (river_id) REFERENCES rivers(id)
ingo@2824: );
ingo@2824: 
ingo@2824: 
ingo@2824: CREATE SEQUENCE FLOW_VELOCITY_MODEL_ID_SEQ;
ingo@2824: 
ingo@2824: CREATE TABLE flow_velocity_model (
ingo@2824:     id                  NUMBER(38,0) NOT NULL,
ingo@2824:     discharge_zone_id   NUMBER(38,0) NOT NULL,
ingo@2824:     description         VARCHAR(256),
ingo@2824:     PRIMARY KEY (id),
ingo@2824:     CONSTRAINT fk_fvm_discharge_zone_id FOREIGN KEY (discharge_zone_id) REFERENCES discharge_zone (id)
ingo@2824: );
ingo@2824: 
ingo@2824: 
ingo@2824: CREATE SEQUENCE FLOW_VELOCITY_M_VALUES_ID_SEQ;
ingo@2824: 
ingo@2824: CREATE TABLE flow_velocity_model_values (
ingo@2824:     id                      NUMBER(38,0) NOT NULL,
ingo@2824:     flow_velocity_model_id  NUMBER(38,0) NOT NULL,
ingo@2824:     station                 NUMBER(38,3) NOT NULL,
ingo@2828:     q                       NUMBER(38,3) NOT NULL,
ingo@2824:     total_channel           NUMBER(38,3) NOT NULL,
ingo@2824:     main_channel            NUMBER(38,3) NOT NULL,
ingo@2824:     shear_stress            NUMBER(38,3) NOT NULL,
ingo@2824:     PRIMARY KEY(id),
ingo@2824:     CONSTRAINT fk_fvv_flow_velocity_model_id FOREIGN KEY (flow_velocity_model_id) REFERENCES flow_velocity_model(id)
ingo@2824: );
ingo@2824: 
ingo@2824: 
ingo@2824: 
ingo@2829: CREATE SEQUENCE FV_MEASURE_ID_SEQ;
ingo@2829: 
ingo@2829: CREATE TABLE flow_velocity_measurements (
ingo@2829:     id          NUMBER(38,0) NOT NULL,
ingo@2829:     river_id    NUMBER(38,0) NOT NULL,
ingo@2829:     description VARCHAR(256),
ingo@2829:     PRIMARY KEY (id),
ingo@2829:     CONSTRAINT fk_fvm_rivers_id FOREIGN KEY (river_id) REFERENCES rivers(id)
ingo@2829: );
ingo@2829: 
ingo@2829: CREATE SEQUENCE FV_MEASURE_VALUES_ID_SEQ;
ingo@2829: 
ingo@2829: CREATE TABLE flow_velocity_measure_values (
ingo@2829:     id              NUMBER(38,0) NOT NULL,
ingo@2829:     measurements_id NUMBER(38,0) NOT NULL,
ingo@2829:     station         NUMBER(38,3) NOT NULL,
ingo@2829:     datetime        TIMESTAMP,
ingo@2829:     w               NUMBER(38,3) NOT NULL,
ingo@2829:     q               NUMBER(38,3) NOT NULL,
ingo@2829:     v               NUMBER(38,3) NOT NULL,
ingo@2829:     description     VARCHAR(256),
ingo@2829:     PRIMARY KEY (id),
ingo@2829:     CONSTRAINT fk_fvmv_measurements_id FOREIGN KEY (measurements_id) REFERENCES flow_velocity_measurements (id)
ingo@2829: );
ingo@2834: 
ingo@2834: 
ingo@2834: CREATE SEQUENCE GRAIN_FRACTION_ID_SEQ;
ingo@2834: 
ingo@2834: CREATE TABLE grain_fraction (
ingo@2834:     id      NUMBER(38,0)   NOT NULL,
ingo@2834:     name    VARCHAR(64)    NOT NULL,
ingo@2834:     lower   NUMBER(38,3),
ingo@2834:     upper   NUMBER(38,3),
ingo@2834:     PRIMARY KEY (id),
ingo@2834: );
ingo@2834: 
ingo@2834: 
ingo@2834: CREATE SEQUENCE SEDIMENT_YIELD_ID_SEQ;
ingo@2834: 
ingo@2834: CREATE TABLE sediment_yield (
ingo@2834:     id                  NUMBER(38,0) NOT NULL,
ingo@2836:     river_id            NUMBER(38,0) NOT NULL,
ingo@2834:     grain_fraction_id   NUMBER(38,0),
ingo@2834:     unit_id             NUMBER(38,0) NOT NULL,
ingo@2834:     time_interval_id    NUMBER(38,0) NOT NULL,
ingo@2840:     description         VARCHAR(256),
ingo@2834:     PRIMARY KEY (id),
ingo@2836:     CONSTRAINT fk_sy_river_id FOREIGN KEY (river_id) REFERENCES rivers(id),
ingo@2834:     CONSTRAINT fk_sy_grain_fraction_id FOREIGN KEY (grain_fraction_id) REFERENCES grain_fraction(id),
ingo@2834:     CONSTRAINT fk_sy_unit_id FOREIGN KEY (unit_id) REFERENCES units(id),
ingo@2834:     CONSTRAINT fk_sy_time_interval_id FOREIGN KEY (time_interval_id) REFERENCES time_intervals(id)
ingo@2834: );
ingo@2834: 
ingo@2834: 
ingo@2834: CREATE SEQUENCE SEDIMENT_YIELD_VALUES_ID_SEQ;
ingo@2834: 
ingo@2834: CREATE TABLE sediment_yield_values (
ingo@2834:     id                  NUMBER(38,0) NOT NULL,
ingo@2834:     sediment_yield_id   NUMBER(38,0) NOT NULL,
ingo@2834:     station             NUMBER(38,3) NOT NULL,
ingo@2834:     value               NUMBER(38,3) NOT NULL,
ingo@2834:     PRIMARY KEY (id),
ingo@2834:     CONSTRAINT fk_syv_sediment_yield_id FOREIGN KEY (sediment_yield_id) REFERENCES sediment_yield(id)
ingo@2834: );
ingo@2841: 
ingo@2841: 
aheinecke@5206: CREATE SEQUENCE MEASUREMENT_STATION_ID_SEQ;
aheinecke@5206: CREATE TABLE measurement_station (
aheinecke@5206:     id                       NUMBER(38)   NOT NULL,
aheinecke@5206:     name                     VARCHAR(256) NOT NULL,
aheinecke@5206:     river_id                 NUMBER(38)   NOT NULL,
aheinecke@5206:     station                  NUMBER(38,3) NOT NULL,
tom@5448:     range_id                 NUMBER(38),
aheinecke@5206:     measurement_type         VARCHAR(64)  NOT NULL,
aheinecke@5206:     riverside                VARCHAR(16),
aheinecke@5206:     reference_gauge_id       NUMBER(38),
tom@5456:     -- store name of reference gauges here too, as not all are in gauges
tom@5453:     reference_gauge_name     VARCHAR(64),
aheinecke@5206:     observation_timerange_id NUMBER(38),
aheinecke@5206:     operator                 VARCHAR(64),
tom@5475:     description              VARCHAR(512),
aheinecke@5206:     PRIMARY KEY              (id),
aheinecke@5206:     CONSTRAINT fk_ms_river_id FOREIGN KEY (river_id) REFERENCES rivers(id) ON DELETE CASCADE,
aheinecke@5206:     CONSTRAINT fk_ms_range_id FOREIGN KEY (range_id) REFERENCES ranges(id) ON DELETE CASCADE,
aheinecke@5206:     CONSTRAINT fk_ms_reference_gauge_id FOREIGN KEY (reference_gauge_id) REFERENCES gauges(id) ON DELETE CASCADE,
tom@5478:     CONSTRAINT fk_ms_observation_timerange_id FOREIGN KEY (observation_timerange_id) REFERENCES time_intervals(id)
aheinecke@5206: );
aheinecke@5206: 
aheinecke@5206: 
ingo@3321: CREATE SEQUENCE SQ_RELATION_ID_SEQ;
ingo@3321: 
ingo@3321: CREATE TABLE sq_relation (
ingo@3321:     id               NUMBER(38,0) NOT NULL,
ingo@3329:     river_id         NUMBER(38,0) NOT NULL,
ingo@3321:     time_interval_id NUMBER(38,0) NOT NULL,
ingo@3321:     description      VARCHAR(256),
ingo@3321:     PRIMARY KEY (id),
ingo@3329:     CONSTRAINT fk_sqr_river_id FOREIGN KEY (river_id) REFERENCES rivers(id),
ingo@3321:     CONSTRAINT fk_sqr_tinterval_id FOREIGN KEY (time_interval_id) REFERENCES time_intervals(id)
ingo@3321: );
ingo@3321: 
ingo@3321: 
ingo@3321: CREATE SEQUENCE SQ_RELATION_VALUES_ID_SEQ;
ingo@3321: 
ingo@3321: CREATE TABLE sq_relation_value (
rrenkert@5426:     id                       NUMBER(38,0) NOT NULL,
rrenkert@5426:     sq_relation_id           NUMBER(38,0) NOT NULL,
rrenkert@5426:     measurement_station_id   NUMBER(38,0) NOT NULL,
tom@5455:     parameter                VARCHAR(1) NOT NULL,
rrenkert@5426:     a                        NUMBER(38,20) NOT NULL,
rrenkert@5426:     b                        NUMBER(38,20) NOT NULL,
tom@5498:     qmax                     NUMBER(38,20) NOT NULL,
rrenkert@5426:     rsq                      NUMBER(38,3),
rrenkert@5426:     ntot                     NUMBER(38,0),
rrenkert@5426:     noutl                    NUMBER(38,0),
rrenkert@5426:     cferguson                NUMBER(38,20),
rrenkert@5426:     cduan                    NUMBER(38,20),
ingo@3321:     PRIMARY KEY (id),
tom@5406:     CONSTRAINT fk_sqr_id FOREIGN KEY (sq_relation_id) REFERENCES sq_relation(id),
tom@5448:     CONSTRAINT fk_mstation_id FOREIGN KEY (measurement_station_id) REFERENCES measurement_station(id)
ingo@3321: );




