blob: 2dce470ae1614f6c450e94970318b30a9f8d3b72 [file] [log] [blame]
Rishi.Chail48830f12020-11-09 03:28:44 +00001CREATE TABLE IF NOT EXISTS RELATION_TYPE
2(
3 RELATION_TYPE TEXT NOT NULL,
4 ID SERIAL PRIMARY KEY
5);
6
7CREATE TABLE IF NOT EXISTS DATASPACE
8(
9 ID SERIAL PRIMARY KEY,
10 NAME TEXT NOT NULL,
11 CONSTRAINT "UQ_NAME" UNIQUE (NAME)
12);
13
14CREATE TABLE IF NOT EXISTS SCHEMA_NODE
15(
16 SCHEMA_NODE_IDENTIFIER TEXT NOT NULL,
17 ID SERIAL PRIMARY KEY
18);
19
Ruslan Kashapovcb035442020-11-24 11:13:43 +020020CREATE 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
29CREATE TABLE IF NOT EXISTS YANG_RESOURCE
30(
31 ID SERIAL PRIMARY KEY,
Ruslan Kashapov4ab9d0e2020-12-10 10:49:59 +020032 NAME TEXT NOT NULL,
Ruslan Kashapovcb035442020-11-24 11:13:43 +020033 CONTENT TEXT NOT NULL,
Ruslan Kashapov4ab9d0e2020-12-10 10:49:59 +020034 CHECKSUM TEXT NOT NULL,
Ruslan Kashapovcb035442020-11-24 11:13:43 +020035 UNIQUE (CHECKSUM)
36);
37
38CREATE 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.Chail48830f12020-11-09 03:28:44 +000045CREATE 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
56CREATE 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
70CREATE 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
80CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_DATASPACE_ID_FK" ON FRAGMENT USING BTREE(DATASPACE_ID) ;
81CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_MODULE_ID_FK" ON FRAGMENT USING BTREE(MODULE_ID) ;
82CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_PARENT_ID_FK" ON FRAGMENT USING BTREE(PARENT_ID) ;
83CREATE INDEX IF NOT EXISTS "FKI_FRAGMENT_ANCHOR_ID_FK" ON FRAGMENT USING BTREE(ANCHOR_ID) ;
84CREATE INDEX IF NOT EXISTS "PERF_SCHEMA_NODE_SCHEMA_NODE_ID" ON SCHEMA_NODE USING BTREE(SCHEMA_NODE_IDENTIFIER) ;
85CREATE INDEX IF NOT EXISTS "FKI_SCHEMA_NODE_ID_TO_ID" ON FRAGMENT USING BTREE(SCHEMA_NODE_ID) ;
86CREATE INDEX IF NOT EXISTS "FKI_RELATION_TYPE_ID_FK" ON RELATION USING BTREE(RELATION_TYPE_ID);
87CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_FROM_ID_FK" ON RELATION USING BTREE(FROM_FRAGMENT_ID);
88CREATE INDEX IF NOT EXISTS "FKI_RELATIONS_TO_ID_FK" ON RELATION USING BTREE(TO_FRAGMENT_ID);
89CREATE INDEX IF NOT EXISTS "PERF_MODULE_MODULE_CONTENT" ON MODULE USING BTREE(MODULE_CONTENT);
Ruslan Kashapovcb035442020-11-24 11:13:43 +020090CREATE UNIQUE INDEX IF NOT EXISTS "UQ_FRAGMENT_XPATH"ON FRAGMENT USING btree(xpath COLLATE pg_catalog."default" text_pattern_ops, dataspace_id);