Fixes #8: merges measurement tables.
This commit is contained in:
parent
68b98f6d6b
commit
01036de04d
10 changed files with 36 additions and 76 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
-- bactdb
|
||||||
|
-- Matthew R Dillon
|
||||||
|
|
||||||
|
DROP TABLE text_measurement_types;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
-- bactdb
|
-- bactdb
|
||||||
-- Matthew R Dillon
|
-- Matthew R Dillon
|
||||||
|
|
||||||
CREATE TABLE text_measurements (
|
CREATE TABLE text_measurement_types (
|
||||||
id BIGSERIAL NOT NULL,
|
id BIGSERIAL NOT NULL,
|
||||||
text_measurement_name CHARACTER VARYING(100),
|
text_measurement_name CHARACTER VARYING(100),
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
-- bactdb
|
|
||||||
-- Matthew R Dillon
|
|
||||||
|
|
||||||
DROP TABLE text_measurements;
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
-- bactdb
|
|
||||||
-- Matthew R Dillon
|
|
||||||
|
|
||||||
DROP TABLE numerical_measurements;
|
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
-- bactdb
|
|
||||||
-- Matthew R Dillon
|
|
||||||
|
|
||||||
CREATE TABLE numerical_measurements (
|
|
||||||
id BIGSERIAL NOT NULL,
|
|
||||||
measurement_value NUMERIC(6, 4) NOT NULL,
|
|
||||||
confidence_interval NUMERIC(6,4) NULL,
|
|
||||||
unit_type_id BIGINT,
|
|
||||||
|
|
||||||
created_at TIMESTAMP WITH TIME ZONE,
|
|
||||||
updated_at TIMESTAMP WITH TIME ZONE,
|
|
||||||
deleted_at TIMESTAMP WITH TIME ZONE,
|
|
||||||
|
|
||||||
CONSTRAINT numerical_measurements_pkey PRIMARY KEY (id),
|
|
||||||
FOREIGN KEY (unit_type_id) REFERENCES unit_types(id)
|
|
||||||
);
|
|
||||||
|
|
30
datastore/migrations/00010_AddStrainObsMeasurements_up.sql
Normal file
30
datastore/migrations/00010_AddStrainObsMeasurements_up.sql
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
-- bactdb
|
||||||
|
-- Matthew R Dillon
|
||||||
|
|
||||||
|
CREATE TABLE strainsobsmeasurements (
|
||||||
|
id BIGSERIAL NOT NULL,
|
||||||
|
strainsobservations_id BIGINT,
|
||||||
|
text_measurement_type_id BIGINT NULL,
|
||||||
|
measurement_value NUMERIC(6, 4) NULL,
|
||||||
|
confidence_interval NUMERIC(6, 4) NULL,
|
||||||
|
unit_type_id BIGINT NULL,
|
||||||
|
|
||||||
|
created_at TIMESTAMP WITH TIME ZONE,
|
||||||
|
updated_at TIMESTAMP WITH TIME ZONE,
|
||||||
|
deleted_at TIMESTAMP WITH TIME ZONE,
|
||||||
|
|
||||||
|
CONSTRAINT strainsobsmeasurements_pkey PRIMARY KEY (id),
|
||||||
|
FOREIGN KEY (strainsobservations_id) REFERENCES strainsobservations(id),
|
||||||
|
FOREIGN KEY (text_measurement_type_id) REFERENCES text_measurement_types(id),
|
||||||
|
FOREIGN KEY (unit_type_id) REFERENCES unit_types(id),
|
||||||
|
CONSTRAINT exclusive_data_type CHECK (
|
||||||
|
(text_measurement_type_id IS NOT NULL
|
||||||
|
AND measurement_value IS NULL
|
||||||
|
AND confidence_interval IS NULL
|
||||||
|
AND unit_type_id IS NULL)
|
||||||
|
OR
|
||||||
|
(text_measurement_type_id IS NULL
|
||||||
|
AND measurement_value IS NOT NULL))
|
||||||
|
|
||||||
|
);
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
-- bactdb
|
|
||||||
-- Matthew R Dillon
|
|
||||||
|
|
||||||
CREATE TABLE strainsobsmeasurements (
|
|
||||||
id BIGSERIAL NOT NULL,
|
|
||||||
strainsobservations_id BIGINT,
|
|
||||||
measurement_table CHARACTER VARYING(15),
|
|
||||||
measurement_id BIGINT,
|
|
||||||
|
|
||||||
created_at TIMESTAMP WITH TIME ZONE,
|
|
||||||
updated_at TIMESTAMP WITH TIME ZONE,
|
|
||||||
deleted_at TIMESTAMP WITH TIME ZONE,
|
|
||||||
|
|
||||||
CONSTRAINT strainsobsmeasurements_pkey PRIMARY KEY (id),
|
|
||||||
FOREIGN KEY (strainsobservations_id) REFERENCES strainsobservations(id)
|
|
||||||
);
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
-- bactdb
|
|
||||||
-- Matthew R Dillon
|
|
||||||
|
|
||||||
DROP VIEW IF EXISTS v_measurements;
|
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
-- bactdb
|
|
||||||
-- Matthew R Dillon
|
|
||||||
|
|
||||||
CREATE OR REPLACE VIEW v_measurements AS
|
|
||||||
SELECT s.strain_name,
|
|
||||||
o.observation_name,
|
|
||||||
som.measurement_table,
|
|
||||||
tm.text_measurement_name,
|
|
||||||
nm.measurement_value,
|
|
||||||
nm.confidence_interval,
|
|
||||||
nm.unit_type_id
|
|
||||||
FROM strainsobsmeasurements som
|
|
||||||
INNER JOIN strainsobservations so
|
|
||||||
ON som.strainsobservations_id = so.id
|
|
||||||
INNER JOIN strains s
|
|
||||||
ON so.strain_id = s.id
|
|
||||||
INNER JOIN observations o
|
|
||||||
ON so.observations_id = o.id
|
|
||||||
LEFT OUTER JOIN text_measurements tm
|
|
||||||
ON som.measurement_id = tm.id
|
|
||||||
AND som.measurement_table = 'text'
|
|
||||||
LEFT OUTER JOIN numerical_measurements nm
|
|
||||||
ON som.measurement_id = nm.id
|
|
||||||
AND som.measurement_table = 'num'
|
|
||||||
ORDER BY measurement_table, o.observation_name ASC
|
|
||||||
|
|
Reference in a new issue