Rishi.Chail | 48830f1 | 2020-11-09 03:28:44 +0000 | [diff] [blame] | 1 | CREATE TABLE IF NOT EXISTS RELATION_TYPE
|
| 2 | (
|
| 3 | RELATION_TYPE TEXT NOT NULL,
|
| 4 | ID SERIAL PRIMARY KEY
|
| 5 | );
|
| 6 |
|
| 7 | CREATE TABLE IF NOT EXISTS DATASPACE
|
| 8 | (
|
| 9 | ID SERIAL PRIMARY KEY,
|
| 10 | NAME TEXT NOT NULL,
|
| 11 | CONSTRAINT "UQ_NAME" UNIQUE (NAME)
|
| 12 | );
|
| 13 |
|
| 14 | CREATE TABLE IF NOT EXISTS SCHEMA_NODE
|
| 15 | (
|
| 16 | SCHEMA_NODE_IDENTIFIER TEXT NOT NULL,
|
| 17 | ID SERIAL PRIMARY KEY
|
| 18 | );
|
| 19 |
|
Ruslan Kashapov | cb03544 | 2020-11-24 11:13:43 +0200 | [diff] [blame] | 20 | CREATE TABLE IF NOT EXISTS SCHEMA_SET
|
| 21 | (
|
| 22 | ID SERIAL PRIMARY KEY,
|
| 23 | NAME TEXT NOT NULL,
|
| 24 | DATASPACE_ID BIGINT NOT NULL,
|
| 25 | UNIQUE (NAME, DATASPACE_ID),
|
| 26 | CONSTRAINT SCHEMA_SET_DATASPACE FOREIGN KEY (DATASPACE_ID) REFERENCES DATASPACE(ID) ON UPDATE CASCADE ON DELETE CASCADE
|
| 27 | );
|
| 28 |
|
| 29 | CREATE TABLE IF NOT EXISTS YANG_RESOURCE
|
| 30 | (
|
| 31 | ID SERIAL PRIMARY KEY,
|
Ruslan Kashapov | 4ab9d0e | 2020-12-10 10:49:59 +0200 | [diff] [blame] | 32 | NAME TEXT NOT NULL,
|
Ruslan Kashapov | cb03544 | 2020-11-24 11:13:43 +0200 | [diff] [blame] | 33 | CONTENT TEXT NOT NULL,
|
Ruslan Kashapov | 4ab9d0e | 2020-12-10 10:49:59 +0200 | [diff] [blame] | 34 | CHECKSUM TEXT NOT NULL,
|
Ruslan Kashapov | cb03544 | 2020-11-24 11:13:43 +0200 | [diff] [blame] | 35 | UNIQUE (CHECKSUM)
|
| 36 | );
|
| 37 |
|
| 38 | CREATE TABLE IF NOT EXISTS SCHEMA_SET_YANG_RESOURCES
|
| 39 | (
|
| 40 | SCHEMA_SET_ID BIGINT NOT NULL,
|
| 41 | YANG_RESOURCE_ID BIGINT NOT NULL REFERENCES YANG_RESOURCE(ID),
|
| 42 | CONSTRAINT SCHEMA_SET_RESOURCE FOREIGN KEY (SCHEMA_SET_ID) REFERENCES SCHEMA_SET(ID) ON DELETE CASCADE
|
| 43 | );
|
| 44 |
|
Rishi.Chail | 48830f1 | 2020-11-09 03:28:44 +0000 | [diff] [blame] | 45 | CREATE TABLE IF NOT EXISTS MODULE
|
| 46 | (
|
| 47 | ID SERIAL PRIMARY KEY,
|
| 48 | NAMESPACE TEXT NOT NULL,
|
| 49 | REVISION TEXT NOT NULL,
|
| 50 | MODULE_CONTENT TEXT NOT NULL,
|
| 51 | DATASPACE_ID BIGINT NOT NULL,
|
| 52 | UNIQUE (DATASPACE_ID, NAMESPACE, REVISION),
|
| 53 | CONSTRAINT MODULE_DATASPACE FOREIGN KEY (DATASPACE_ID) REFERENCES DATASPACE (id) ON UPDATE CASCADE ON DELETE CASCADE
|
| 54 | );
|
| 55 |
|
| 56 | CREATE TABLE IF NOT EXISTS FRAGMENT
|
| 57 | (
|
| 58 | ID BIGSERIAL PRIMARY KEY,
|
| 59 | XPATH TEXT NOT NULL,
|
| 60 | ATTRIBUTES JSONB,
|
| 61 | ANCHOR_NAME TEXT,
|
| 62 | ANCHOR_ID BIGINT REFERENCES FRAGMENT(ID),
|
| 63 | PARENT_ID BIGINT REFERENCES FRAGMENT(ID),
|
| 64 | MODULE_ID INTEGER REFERENCES MODULE(ID),
|
| 65 | DATASPACE_ID INTEGER NOT NULL REFERENCES DATASPACE(ID),
|
| 66 | SCHEMA_NODE_ID INTEGER REFERENCES SCHEMA_NODE(ID),
|
| 67 | UNIQUE (DATASPACE_ID, ANCHOR_NAME, XPATH)
|
| 68 | );
|
| 69 |
|
| 70 | CREATE TABLE IF NOT EXISTS RELATION
|
| 71 | (
|
| 72 | FROM_FRAGMENT_ID BIGINT NOT NULL REFERENCES FRAGMENT(ID),
|
| 73 | TO_FRAGMENT_ID BIGINT NOT NULL REFERENCES FRAGMENT(ID),
|
| 74 | RELATION_TYPE_ID INTEGER NOT NULL REFERENCES RELATION_TYPE(ID),
|
| 75 | FROM_REL_XPATH TEXT NOT NULL,
|
| 76 | TO_REL_XPATH TEXT NOT NULL,
|
| 77 | CONSTRAINT RELATION_PKEY PRIMARY KEY (TO_FRAGMENT_ID, FROM_FRAGMENT_ID, RELATION_TYPE_ID)
|
| 78 | );
|
| 79 |
|
| 80 | CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_DATASPACE_ID_FK" ON FRAGMENT USING BTREE(DATASPACE_ID) ;
|
| 81 | CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_MODULE_ID_FK" ON FRAGMENT USING BTREE(MODULE_ID) ;
|
| 82 | CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_PARENT_ID_FK" ON FRAGMENT USING BTREE(PARENT_ID) ;
|
| 83 | CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_ANCHOR_ID_FK" ON FRAGMENT USING BTREE(ANCHOR_ID) ;
|
| 84 | CREATE INDEX IF NOT EXISTS "PERF_SCHEMA_NODE_SCHEMA_NODE_ID" ON SCHEMA_NODE USING BTREE(SCHEMA_NODE_IDENTIFIER) ;
|
| 85 | CREATE INDEX IF NOT EXISTS "FKI_SCHEMA_NODE_ID_TO_ID" ON FRAGMENT USING BTREE(SCHEMA_NODE_ID) ;
|
| 86 | CREATE INDEX IF NOT EXISTS "FKI_RELATION_TYPE_ID_FK" ON RELATION USING BTREE(RELATION_TYPE_ID);
|
| 87 | CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_FROM_ID_FK" ON RELATION USING BTREE(FROM_FRAGMENT_ID);
|
| 88 | CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_TO_ID_FK" ON RELATION USING BTREE(TO_FRAGMENT_ID);
|
| 89 | CREATE INDEX IF NOT EXISTS "PERF_MODULE_MODULE_CONTENT" ON MODULE USING BTREE(MODULE_CONTENT);
|
Ruslan Kashapov | cb03544 | 2020-11-24 11:13:43 +0200 | [diff] [blame] | 90 | CREATE UNIQUE INDEX IF NOT EXISTS "UQ_FRAGMENT_XPATH"ON FRAGMENT USING btree(xpath COLLATE pg_catalog."default" text_pattern_ops, dataspace_id);
|