diff --git a/db/schema.sql b/db/schema.sql index 5557ae8..7d787dd 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -1,4 +1,6 @@ -CREATE TABLE dataset ( +CREATE schema dict; + +CREATE TABLE dict.dataset ( DATASET_ID INT GENERATED ALWAYS AS IDENTITY, REF VARCHAR(512) NOT NULL, FULL_NAME VARCHAR(512) NOT NULL, @@ -8,16 +10,16 @@ CREATE TABLE dataset ( UNIQUE (REF) ); -CREATE TABLE dataset_meta ( +CREATE TABLE dict.dataset_meta ( DATASET_META_ID INT GENERATED ALWAYS AS IDENTITY, DATASET_ID INT NOT NULL, KEY VARCHAR(256) NOT NULL, VALUE TEXT NOT NULL, UNIQUE (KEY, DATASET_ID), - CONSTRAINT fk_study FOREIGN KEY(DATASET_ID) REFERENCES dataset(DATASET_ID) + CONSTRAINT fk_study FOREIGN KEY(DATASET_ID) REFERENCES dict.dataset(DATASET_ID) ); -CREATE TABLE consent ( +CREATE TABLE dict.consent ( CONSENT_ID INT GENERATED ALWAYS AS IDENTITY, DATASET_ID INT NOT NULL, CONSENT_CODE VARCHAR(512) NOT NULL, @@ -27,7 +29,7 @@ CREATE TABLE consent ( UNIQUE (CONSENT_CODE, DATASET_ID) ); -CREATE TABLE concept_node ( +CREATE TABLE dict.concept_node ( CONCEPT_NODE_ID INT GENERATED ALWAYS AS IDENTITY, DATASET_ID INT NOT NULL, NAME VARCHAR(512) NOT NULL, @@ -36,21 +38,21 @@ CREATE TABLE concept_node ( CONCEPT_PATH VARCHAR(10000) NOT NULL DEFAULT 'INVALID', PARENT_ID INT, PRIMARY KEY (CONCEPT_NODE_ID), - CONSTRAINT fk_parent FOREIGN KEY (PARENT_ID) REFERENCES CONCEPT_NODE(CONCEPT_NODE_ID), - CONSTRAINT fk_study FOREIGN KEY (DATASET_ID) REFERENCES dataset(DATASET_ID) + CONSTRAINT fk_parent FOREIGN KEY (PARENT_ID) REFERENCES dict.CONCEPT_NODE(CONCEPT_NODE_ID), + CONSTRAINT fk_study FOREIGN KEY (DATASET_ID) REFERENCES dict.dataset(DATASET_ID) ); -CREATE UNIQUE INDEX concept_node_concept_path_idx ON CONCEPT_NODE (md5(CONCEPT_PATH)); +CREATE UNIQUE INDEX concept_node_concept_path_idx ON dict.CONCEPT_NODE (md5(CONCEPT_PATH)); -CREATE TABLE concept_node_meta ( +CREATE TABLE dict.concept_node_meta ( CONCEPT_NODE_META_ID INT GENERATED ALWAYS AS IDENTITY, CONCEPT_NODE_ID INT NOT NULL, KEY VARCHAR(256) NOT NULL, VALUE TEXT NOT NULL, PRIMARY KEY (CONCEPT_NODE_META_ID), UNIQUE (KEY, CONCEPT_NODE_ID), - CONSTRAINT fk_CONCEPT_NODE FOREIGN KEY (CONCEPT_NODE_ID) REFERENCES CONCEPT_NODE(CONCEPT_NODE_ID) + CONSTRAINT fk_CONCEPT_NODE FOREIGN KEY (CONCEPT_NODE_ID) REFERENCES dict.CONCEPT_NODE(CONCEPT_NODE_ID) ); -CREATE TABLE facet_category ( +CREATE TABLE dict.facet_category ( FACET_CATEGORY_ID INT GENERATED ALWAYS AS IDENTITY, NAME VARCHAR(512) NOT NULL, DISPLAY VARCHAR(512) NOT NULL, @@ -59,7 +61,7 @@ CREATE TABLE facet_category ( UNIQUE (NAME) ); -CREATE TABLE facet ( +CREATE TABLE dict.facet ( FACET_ID INT GENERATED ALWAYS AS IDENTITY, FACET_CATEGORY_ID INT NOT NULL, NAME VARCHAR(512) NOT NULL, @@ -68,41 +70,41 @@ CREATE TABLE facet ( PARENT_ID INT, PRIMARY KEY (FACET_ID), UNIQUE (NAME, FACET_CATEGORY_ID), - CONSTRAINT fk_parent FOREIGN KEY (PARENT_ID) REFERENCES facet(FACET_ID), - CONSTRAINT fk_category FOREIGN KEY (FACET_CATEGORY_ID) REFERENCES facet_category(FACET_CATEGORY_ID) + CONSTRAINT fk_parent FOREIGN KEY (PARENT_ID) REFERENCES dict.facet(FACET_ID), + CONSTRAINT fk_category FOREIGN KEY (FACET_CATEGORY_ID) REFERENCES dict.facet_category(FACET_CATEGORY_ID) ); -CREATE TABLE facet_meta ( +CREATE TABLE dict.facet_meta ( FACET_META_ID INT GENERATED ALWAYS AS IDENTITY, FACET_ID INT NOT NULL, KEY VARCHAR(256) NOT NULL, VALUE TEXT NOT NULL, UNIQUE (KEY, FACET_ID), - CONSTRAINT fk_facet FOREIGN KEY(FACET_ID) REFERENCES facet(FACET_ID) + CONSTRAINT fk_facet FOREIGN KEY(FACET_ID) REFERENCES dict.facet(FACET_ID) ); -CREATE TABLE facet_category_meta ( +CREATE TABLE dict.facet_category_meta ( FACET_CATEGORY_META_ID INT GENERATED ALWAYS AS IDENTITY, FACET_CATEGORY_ID INT NOT NULL, KEY VARCHAR(256) NOT NULL, VALUE TEXT NOT NULL, UNIQUE (KEY, FACET_CATEGORY_ID), - CONSTRAINT fk_facet_category FOREIGN KEY(FACET_CATEGORY_ID) REFERENCES facet_category(FACET_CATEGORY_ID) + CONSTRAINT fk_facet_category FOREIGN KEY(FACET_CATEGORY_ID) REFERENCES dict.facet_category(FACET_CATEGORY_ID) ); -CREATE TABLE facet__concept_node ( +CREATE TABLE dict.facet__concept_node ( FACET__CONCEPT_NODE_ID INT GENERATED ALWAYS AS IDENTITY, FACET_ID INT NOT NULL, CONCEPT_NODE_ID INT NOT NULL, PRIMARY KEY (FACET__CONCEPT_NODE_ID), UNIQUE (FACET_ID, CONCEPT_NODE_ID), - CONSTRAINT fk_facet FOREIGN KEY (FACET_ID) REFERENCES facet(FACET_ID), - CONSTRAINT fk_concept_node FOREIGN KEY (CONCEPT_NODE_ID) REFERENCES concept_node(CONCEPT_NODE_ID) + CONSTRAINT fk_facet FOREIGN KEY (FACET_ID) REFERENCES dict.facet(FACET_ID), + CONSTRAINT fk_concept_node FOREIGN KEY (CONCEPT_NODE_ID) REFERENCES dict.concept_node(CONCEPT_NODE_ID) ); -- Commenting out because I don't remember what these do. ---CREATE TABLE harmonized_concept_node ( +--CREATE TABLE dict.harmonized_concept_node ( -- HARMONIZED_CONCEPT_NODE_ID INT GENERATED ALWAYS AS IDENTITY, -- NAME VARCHAR(512) NOT NULL, -- DISPLAY VARCHAR(512) NOT NULL, @@ -113,7 +115,7 @@ CREATE TABLE facet__concept_node ( --); --CREATE UNIQUE INDEX harmonized_concept_node_concept_path_idx ON harmonized_concept_node(md5(CONCEPT_PATH)); -- ---CREATE TABLE harmonized_concept_node__concept_node ( +--CREATE TABLE dict.harmonized_concept_node__concept_node ( -- HARMONIZED_CONCEPT_NODE__CONCEPT_NODE INT GENERATED ALWAYS AS IDENTITY, -- HARMONIZED_CONCEPT_NODE_ID INT NOT NULL, -- CONCEPT_NODE_ID INT NOT NULL,