diff --git a/chado/migrations/V1.3.3.010__add_environmental_fact_table.sql b/chado/migrations/V1.3.3.010__add_environmental_fact_table.sql new file mode 100644 index 000000000..a31f441ab --- /dev/null +++ b/chado/migrations/V1.3.3.010__add_environmental_fact_table.sql @@ -0,0 +1,16 @@ +-- Adds a new "nd_fact" table to store environmental data. +CREATE TABLE nd_fact( + nd_fact_id BIGSERIAL PRIMARY KEY NOT NULL, + nd_geolocation_id BIGINT NOT NULL REFERENCES nd_geolocation (nd_geolocation_id) ON DELETE CASCADE INITIALLY DEFERRED, + type_id BIGINT NOT NULL REFERENCES cvterm (cvterm_id) ON DELETE CASCADE INITIALLY DEFERRED, + timecaptured TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + timecapturedend TIMESTAMP, + value TEXT NULL, + CONSTRAINT nd_fact_c1 UNIQUE (nd_geolocation_id, type_id, timecaptured) + ); +CREATE INDEX nd_fact_idx1 ON nd_fact (nd_geolocation_id); +CREATE INDEX nd_fact_idx2 ON nd_fact (timecaptured); + +COMMENT ON TABLE nd_fact IS 'The fact table contains facts (temparture, weather condition,...) at a given time for a given geolocation.'; +COMMENT ON COLUMN nd_fact.value IS 'The value can be NULL if the type_id is self-explicit. For instance, if the type_id term is "sunny day", there is no need for a value.'; +COMMENT ON COLUMN nd_fact.timecapturedend IS 'This optional value can be used to mark the end of the time that the catured fact data refers to, that is to provide a time span rather than a time point; can be null.'; diff --git a/chado/modules/natural_diversity/natural_diversity.sql b/chado/modules/natural_diversity/natural_diversity.sql index 9678f4ea3..4e599fa5b 100644 --- a/chado/modules/natural_diversity/natural_diversity.sql +++ b/chado/modules/natural_diversity/natural_diversity.sql @@ -435,3 +435,23 @@ CREATE INDEX nd_experiment_analysis_idx2 ON nd_experiment_analysis (analysis_id) CREATE INDEX nd_experiment_analysis_idx3 ON nd_experiment_analysis (type_id); COMMENT ON TABLE nd_experiment_analysis IS 'An analysis that is used in an experiment'; + +-- ================================================ +-- TABLE: nd_fact +-- ================================================ + +CREATE TABLE nd_fact( + nd_fact_id BIGSERIAL PRIMARY KEY NOT NULL, + nd_geolocation_id BIGINT NOT NULL REFERENCES nd_geolocation (nd_geolocation_id) ON DELETE CASCADE INITIALLY DEFERRED, + type_id BIGINT NOT NULL REFERENCES cvterm (cvterm_id) ON DELETE CASCADE INITIALLY DEFERRED, + timecaptured TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + timecapturedend TIMESTAMP, + value TEXT NULL, + CONSTRAINT nd_fact_c1 UNIQUE (nd_geolocation_id, type_id, timecaptured) + ); +CREATE INDEX nd_fact_idx1 ON nd_fact (nd_geolocation_id); +CREATE INDEX nd_fact_idx2 ON nd_fact (timecaptured); + +COMMENT ON TABLE nd_fact IS 'The fact table contains facts (temparture, weather condition,...) at a given time for a given geolocation.'; +COMMENT ON COLUMN nd_fact.value IS 'The value can be NULL if the type_id is self-explicit. For instance, if the type_id term is "sunny day", there is no need for a value.'; +COMMENT ON COLUMN nd_fact.timecapturedend IS 'This optional value can be used to mark the end of the time that the catured fact data refers to, that is to provide a time span rather than a time point; can be null.';