|
| 1 | +-- Dec 12, 2025 |
| 2 | +-- Adding SEQUENCEs and support tables for sample_idx, prep_sample_idx, |
| 3 | +-- and artifact_sample_idx |
| 4 | + |
| 5 | +CREATE SEQUENCE sequence_sample_idx AS BIGINT; |
| 6 | +CREATE TABLE map_sample_idx ( |
| 7 | + sample_name VARCHAR NOT NULL PRIMARY KEY, |
| 8 | + study_idx BIGINT NOT NULL, |
| 9 | + sample_idx BIGINT DEFAULT NEXTVAL('sequence_sample_idx') NOT NULL, |
| 10 | + UNIQUE (study_idx, sample_idx), |
| 11 | + UNIQUE (sample_idx), |
| 12 | + CONSTRAINT fk_study FOREIGN KEY (study_idx) REFERENCES qiita.study (study_id) |
| 13 | +); |
| 14 | + |
| 15 | +CREATE SEQUENCE sequence_prep_sample_idx AS BIGINT; |
| 16 | +CREATE TABLE map_prep_sample_idx ( |
| 17 | + prep_sample_idx BIGINT NOT NULL PRIMARY KEY DEFAULT NEXTVAL('sequence_prep_sample_idx'), |
| 18 | + prep_idx BIGINT NOT NULL, |
| 19 | + sample_idx BIGINT NOT NULL, |
| 20 | + UNIQUE (prep_idx, prep_sample_idx), |
| 21 | + CONSTRAINT fk_prep_template FOREIGN KEY (prep_idx) REFERENCES qiita.prep_template (prep_template_id) |
| 22 | +); |
| 23 | + |
| 24 | +CREATE SEQUENCE sequence_artifact_sample_idx AS BIGINT; |
| 25 | +CREATE TABLE map_artifact_sample_idx ( |
| 26 | + artifact_sample_idx BIGINT NOT NULL PRIMARY KEY DEFAULT NEXTVAL('sequence_artifact_sample_idx'), |
| 27 | + artifact_idx BIGINT NOT NULL, |
| 28 | + prep_sample_idx BIGINT NOT NULL, |
| 29 | + UNIQUE (artifact_idx, artifact_sample_idx), |
| 30 | + CONSTRAINT fk_artifact FOREIGN KEY (artifact_idx) REFERENCES qiita.artifact (artifact_id) |
| 31 | +); |
0 commit comments