Skip to content

Commit

Permalink
fix deleted migrations, delete future data tables, add various timesc…
Browse files Browse the repository at this point in the history
…ale data
  • Loading branch information
ethanrdsch committed Aug 15, 2024
1 parent 4633f94 commit a6b90f3
Show file tree
Hide file tree
Showing 13 changed files with 8,563 additions and 0 deletions.
61 changes: 61 additions & 0 deletions backend/migrations/20230920100538_add_future_data_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
-- setup table for models, as each dataset can have multiple models
CREATE TABLE future_model (
id SERIAL NOT NULL,
name TEXT NOT NULL,
dataset INT NOT NULL,
source SMALLINT NOT NULL,
domain float8 [] NOT NULL DEFAULT '{}',
PRIMARY KEY(id),
FOREIGN KEY(dataset) REFERENCES dataset(id),
FOREIGN KEY(source) REFERENCES data_source(id)
);

-- each year will have a different confidence interval, so setup tables to store that information
-- stores upper ci for a county/country
CREATE TABLE ci_above (
id SERIAL NOT NULL,
model INT NOT NULL,
geo_id SMALLINT NOT NULL,
PRIMARY KEY (id)
);

-- stores lower ci for a county/country
CREATE TABLE ci_below (
id SERIAL NOT NULL,
model INT NOT NULL,
geo_id SMALLINT NOT NULL,
PRIMARY KEY (id)
);

-- setup table for future/predictive data
CREATE TABLE future_data (
model INT NOT NULL,
ci_above INT,
ci_below INT,
start_date DATE NOT NULL,
end_date DATE NOT NULL,
interval SMALLINT NOT NULL,
id SMALLINT NOT NULL,
geography_type INT NOT NULL,
PRIMARY KEY (
model,
start_date,
end_date,
id
),
FOREIGN KEY (model) REFERENCES future_model(id),
FOREIGN KEY (ci_above) REFERENCES ci_above(id),
FOREIGN KEY (ci_below) REFERENCES ci_below(id),
CONSTRAINT data_geo_ids_fkey FOREIGN KEY (geography_type, id) REFERENCES geo_id (geography_type, id)
);

-- add columns for years up to 2200
DO $$
DECLARE
cur_year INT := 2024;
BEGIN
WHILE cur_year <2201 LOOP
EXECUTE 'ALTER TABLE future_data ADD value_' || cur_year || ' FLOAT';
cur_year := cur_year+1;
END LOOP;
END$$;
3 changes: 3 additions & 0 deletions backend/migrations/20230921144639_remove-model-domain.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Remove domain from future model table, as future data already has a start and end date
ALTER TABLE
future_model DROP COLUMN domain;
5 changes: 5 additions & 0 deletions backend/migrations/20230921145028_description-for-model.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Add column for a description
ALTER TABLE
future_model
ADD
COLUMN description TEXT;
5 changes: 5 additions & 0 deletions backend/migrations/20240810112520_drop-future-tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- future data visualization is not ready yet, so no need for the tables currently
DROP TABLE IF EXISTS future_data;
DROP TABLE IF EXISTS ci_above;
DROP TABLE IF EXISTS ci_below;
DROP TABLE IF EXISTS future_model;
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
INSERT INTO
dataset (
short_name,
name,
description,
units,
geography_type
)
VALUES
(
'cmi_MERRA2_ERA5',
'cmi_MERRA2_ERA5',
'placeholder',
'',
2
),
(
'dry_MERRA2_ERA5',
'dry_MERRA2_ERA5',
'placeholder',
'',
2
),
(
'gw_MERRA2_ERA5',
'gw_MERRA2_ERA5',
'placeholder',
'',
2
),
(
'ht_MERRA2_ERA5',
'ht_MERRA2_ERA5',
'placeholder',
'',
2
),
(
'pet_MERRA2_ERA5',
'pet_MERRA2_ERA5',
'placeholder',
'',
2
),
(
'prc_MERRA2_ERA5',
'prc_MERRA2_ERA5',
'placeholder',
'',
2
),
(
'ro_MERRA2_ERA5',
'ro_MERRA2_ERA5',
'placeholder',
'',
2
),
(
'wet_MERRA2_ERA5',
'wet_MERRA2_ERA5',
'placeholder',
'',
2
);
Loading

0 comments on commit a6b90f3

Please sign in to comment.