diff options
author | 2020-11-12 23:17:20 -0500 | |
---|---|---|
committer | 2020-11-16 15:55:09 +0000 | |
commit | ec650124e318a19a5a9b18fca134fb7fd46bd91e (patch) | |
tree | 0343fc3203c3ec1ed4fe9a2914290e85d6a8659c | |
parent | 0faa2695763f279f6329f56d7d2c6376292de5a3 (diff) |
Fix init db schema script
Issue-ID: CPS-82
Signed-off-by: Bruno Sakoto <bruno.sakoto@bell.ca>
Change-Id: I8c719935b78aaeab9d2f7a0af91b2192df897eb1
-rw-r--r-- | cps-ri/src/main/resources/schema.sql | 125 |
1 files changed, 63 insertions, 62 deletions
diff --git a/cps-ri/src/main/resources/schema.sql b/cps-ri/src/main/resources/schema.sql index 6a76fbd19..ba05048e8 100644 --- a/cps-ri/src/main/resources/schema.sql +++ b/cps-ri/src/main/resources/schema.sql @@ -1,63 +1,64 @@ -CREATE TABLE IF NOT EXISTS RELATION_TYPE
-(
- RELATION_TYPE TEXT NOT NULL,
- ID SERIAL PRIMARY KEY
-);
-
-CREATE TABLE IF NOT EXISTS DATASPACE
-(
- ID SERIAL PRIMARY KEY,
- NAME TEXT NOT NULL,
- CONSTRAINT "UQ_NAME" UNIQUE (NAME)
-);
-
-CREATE TABLE IF NOT EXISTS SCHEMA_NODE
-(
- SCHEMA_NODE_IDENTIFIER TEXT NOT NULL,
- ID SERIAL PRIMARY KEY
-);
-
-CREATE TABLE IF NOT EXISTS FRAGMENT
-(
- ID BIGSERIAL PRIMARY KEY,
- XPATH TEXT NOT NULL,
- DATASPACE_ID INTEGER NOT NULL REFERENCES DATASPACE(ID),
- ATTRIBUTES JSONB,
- ANCHOR_ID BIGINT REFERENCES FRAGMENT(ID),
- PARENT_ID BIGINT REFERENCES FRAGMENT(ID),
- MODULE_SET_ID INTEGER REFERENCES MODULE_SET(ID),
- SCHEMA_NODE_ID INTEGER REFERENCES SCHEMA_NODE(ID)
-);
-
-CREATE TABLE IF NOT EXISTS RELATION
-(
- FROM_FRAGMENT_ID BIGINT NOT NULL REFERENCES FRAGMENT(ID),
- TO_FRAGMENT_ID BIGINT NOT NULL REFERENCES FRAGMENT(ID),
- RELATION_TYPE_ID INTEGER NOT NULL REFERENCES RELATION_TYPE(ID),
- FROM_REL_XPATH TEXT NOT NULL,
- TO_REL_XPATH TEXT NOT NULL,
- CONSTRAINT RELATION_PKEY PRIMARY KEY (TO_FRAGMENT_ID, FROM_FRAGMENT_ID, RELATION_TYPE_ID)
-);
-
-CREATE TABLE IF NOT EXISTS MODULE
-(
- NAMESPACE TEXT NOT NULL,
- REVISION TEXT NOT NULL,
- MODULE_CONTENT TEXT NOT NULL,
- DATASPACE_ID BIGINT NOT NULL,
- ID SERIAL PRIMARY KEY,
- UNIQUE (NAMESPACE, REVISION),
- CONSTRAINT module_dataspace FOREIGN KEY (DATASPACE_ID) REFERENCES DATASPACE (id) ON UPDATE CASCADE ON DELETE CASCADE
-);
-
-CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_DATASPACE_ID_FK" ON FRAGMENT USING BTREE(DATASPACE_ID) ;
-CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_MODULE_SET_ID_FK" ON FRAGMENT USING BTREE(MODULE_SET_ID) ;
-CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_PARENT_ID_FK" ON FRAGMENT USING BTREE(PARENT_ID) ;
-CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_ANCHOR_ID_FK" ON FRAGMENT USING BTREE(ANCHOR_ID) ;
-CREATE INDEX IF NOT EXISTS "PERF_SCHEMA_NODE_SCHEMA_NODE_ID" ON SCHEMA_NODE USING BTREE(SCHEMA_NODE_IDENTIFIER) ;
-CREATE INDEX IF NOT EXISTS "FKI_SCHEMA_NODE_ID_TO_ID" ON FRAGMENT USING BTREE(SCHEMA_NODE_ID) ;
-CREATE INDEX IF NOT EXISTS "FKI_RELATION_TYPE_ID_FK" ON RELATION USING BTREE(RELATION_TYPE_ID);
-CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_FROM_ID_FK" ON RELATION USING BTREE(FROM_FRAGMENT_ID);
-CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_TO_ID_FK" ON RELATION USING BTREE(TO_FRAGMENT_ID);
-CREATE INDEX IF NOT EXISTS "PERF_MODULE_SET_MODULE_SET_REFERENCE" ON MODULE_SET USING BTREE(MODULE_SET_REFERENCE) ;
+CREATE TABLE IF NOT EXISTS RELATION_TYPE +( + RELATION_TYPE TEXT NOT NULL, + ID SERIAL PRIMARY KEY +); + +CREATE TABLE IF NOT EXISTS DATASPACE +( + ID SERIAL PRIMARY KEY, + NAME TEXT NOT NULL, + CONSTRAINT "UQ_NAME" UNIQUE (NAME) +); + +CREATE TABLE IF NOT EXISTS SCHEMA_NODE +( + SCHEMA_NODE_IDENTIFIER TEXT NOT NULL, + ID SERIAL PRIMARY KEY +); + +CREATE TABLE IF NOT EXISTS MODULE +( + NAMESPACE TEXT NOT NULL, + REVISION TEXT NOT NULL, + MODULE_CONTENT TEXT NOT NULL, + DATASPACE_ID BIGINT NOT NULL, + ID SERIAL PRIMARY KEY, + UNIQUE (DATASPACE_ID, NAMESPACE, REVISION), + CONSTRAINT module_dataspace FOREIGN KEY (DATASPACE_ID) REFERENCES DATASPACE (id) ON UPDATE CASCADE ON DELETE CASCADE +); + +CREATE TABLE IF NOT EXISTS FRAGMENT +( + ID BIGSERIAL PRIMARY KEY, + XPATH TEXT NOT NULL, + DATASPACE_ID INTEGER NOT NULL REFERENCES DATASPACE(ID), + ATTRIBUTES JSONB, + ANCHOR_ID BIGINT REFERENCES FRAGMENT(ID), + PARENT_ID BIGINT REFERENCES FRAGMENT(ID), + MODULE_ID INTEGER REFERENCES MODULE(ID), + SCHEMA_NODE_ID INTEGER REFERENCES SCHEMA_NODE(ID) +); + +CREATE TABLE IF NOT EXISTS RELATION +( + FROM_FRAGMENT_ID BIGINT NOT NULL REFERENCES FRAGMENT(ID), + TO_FRAGMENT_ID BIGINT NOT NULL REFERENCES FRAGMENT(ID), + RELATION_TYPE_ID INTEGER NOT NULL REFERENCES RELATION_TYPE(ID), + FROM_REL_XPATH TEXT NOT NULL, + TO_REL_XPATH TEXT NOT NULL, + CONSTRAINT RELATION_PKEY PRIMARY KEY (TO_FRAGMENT_ID, FROM_FRAGMENT_ID, RELATION_TYPE_ID) +); + + +CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_DATASPACE_ID_FK" ON FRAGMENT USING BTREE(DATASPACE_ID) ; +CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_MODULE_ID_FK" ON FRAGMENT USING BTREE(MODULE_ID) ; +CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_PARENT_ID_FK" ON FRAGMENT USING BTREE(PARENT_ID) ; +CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_ANCHOR_ID_FK" ON FRAGMENT USING BTREE(ANCHOR_ID) ; +CREATE INDEX IF NOT EXISTS "PERF_SCHEMA_NODE_SCHEMA_NODE_ID" ON SCHEMA_NODE USING BTREE(SCHEMA_NODE_IDENTIFIER) ; +CREATE INDEX IF NOT EXISTS "FKI_SCHEMA_NODE_ID_TO_ID" ON FRAGMENT USING BTREE(SCHEMA_NODE_ID) ; +CREATE INDEX IF NOT EXISTS "FKI_RELATION_TYPE_ID_FK" ON RELATION USING BTREE(RELATION_TYPE_ID); +CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_FROM_ID_FK" ON RELATION USING BTREE(FROM_FRAGMENT_ID); +CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_TO_ID_FK" ON RELATION USING BTREE(TO_FRAGMENT_ID); +CREATE INDEX IF NOT EXISTS "PERF_MODULE_MODULE_CONTENT" ON MODULE USING BTREE(MODULE_CONTENT); CREATE UNIQUE INDEX IF NOT EXISTS "UQ_FRAGMENT_XPATH"ON FRAGMENT USING btree(xpath COLLATE pg_catalog."default" text_pattern_ops, dataspace_id);
\ No newline at end of file |