Merge "Condense Liquibase steps"
[cps.git] / cps-ri / src / main / resources / changelog / db / changes / 01-createCPSTables.yaml
1 # ============LICENSE_START=======================================================
2 # Copyright (c) 2021 Bell Canada.
3 # ================================================================================
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ============LICENSE_END=========================================================
16
17 # For legacy reasons, previous files for changeset Ids: 6, 11, 15, 17-21 have been condensed into this file.
18 databaseChangeLog:
19   - changeSet:
20       id: 1-1
21       author: cps
22       changes:
23         - createTable:
24             columns:
25               - column:
26                   autoIncrement: true
27                   constraints:
28                     nullable: false
29                     primaryKey: true
30                     primaryKeyName: anchor_pkey
31                   name: id
32                   type: BIGINT
33               - column:
34                   name: name
35                   type: TEXT
36               - column:
37                   name: schema_set_id
38                   type: INTEGER
39               - column:
40                   constraints:
41                     nullable: false
42                   name: dataspace_id
43                   type: INTEGER
44             tableName: anchor
45   - changeSet:
46       id: 1-2
47       author: cps
48       changes:
49         - createTable:
50             columns:
51               - column:
52                   constraints:
53                     nullable: false
54                   name: from_fragment_id
55                   type: BIGINT
56               - column:
57                   constraints:
58                     nullable: false
59                   name: to_fragment_id
60                   type: BIGINT
61               - column:
62                   constraints:
63                     nullable: false
64                   name: relation_type_id
65                   type: INTEGER
66               - column:
67                   constraints:
68                     nullable: false
69                   name: from_rel_xpath
70                   type: TEXT
71               - column:
72                   constraints:
73                     nullable: false
74                   name: to_rel_xpath
75                   type: TEXT
76             tableName: relation
77   - changeSet:
78       id: 1-3
79       author: cps
80       changes:
81         - createTable:
82             columns:
83               - column:
84                   constraints:
85                     nullable: false
86                   name: relation_type
87                   type: TEXT
88               - column:
89                   autoIncrement: true
90                   constraints:
91                     nullable: false
92                     primaryKey: true
93                     primaryKeyName: relation_type_pkey
94                   name: id
95                   type: INTEGER
96             tableName: relation_type
97   - changeSet:
98       id: 1-4
99       author: cps
100       changes:
101         - createTable:
102             columns:
103               - column:
104                   autoIncrement: true
105                   constraints:
106                     nullable: false
107                     primaryKey: true
108                     primaryKeyName: fragment_pkey
109                   name: id
110                   type: BIGINT
111               - column:
112                   constraints:
113                     nullable: false
114                   name: xpath
115                   type: TEXT
116               - column:
117                   name: attributes
118                   type: JSONB
119               - column:
120                   name: anchor_id
121                   type: BIGINT
122               - column:
123                   name: parent_id
124                   type: BIGINT
125               - column:
126                   constraints:
127                     nullable: false
128                   name: dataspace_id
129                   type: INTEGER
130               - column:
131                   name: schema_node_id
132                   type: INTEGER
133             tableName: fragment
134   - changeSet:
135       id: 1-5
136       author: cps
137       changes:
138         - createTable:
139             columns:
140               - column:
141                   autoIncrement: true
142                   constraints:
143                     nullable: false
144                     primaryKey: true
145                     primaryKeyName: schema_set_pkey
146                   name: id
147                   type: INTEGER
148               - column:
149                   constraints:
150                     nullable: false
151                   name: name
152                   type: TEXT
153               - column:
154                   constraints:
155                     nullable: false
156                   name: dataspace_id
157                   type: BIGINT
158             tableName: schema_set
159   - changeSet:
160       id: 1-6
161       author: cps
162       changes:
163         - createTable:
164             columns:
165               - column:
166                   autoIncrement: true
167                   constraints:
168                     nullable: false
169                     primaryKey: true
170                     primaryKeyName: yang_resource_pkey
171                   name: id
172                   type: INTEGER
173               - column:
174                   constraints:
175                     nullable: false
176                   name: name
177                   type: TEXT
178               - column:
179                   constraints:
180                     nullable: false
181                   name: content
182                   type: TEXT
183               - column:
184                   constraints:
185                     nullable: false
186                   name: checksum
187                   type: TEXT
188             tableName: yang_resource
189   - changeSet:
190       id: 1-7
191       author: cps
192       changes:
193         - createTable:
194             columns:
195               - column:
196                   autoIncrement: true
197                   constraints:
198                     nullable: false
199                     primaryKey: true
200                     primaryKeyName: dataspace_pkey
201                   name: id
202                   type: INTEGER
203               - column:
204                   constraints:
205                     nullable: false
206                   name: name
207                   type: TEXT
208             tableName: dataspace
209   - changeSet:
210       id: 1-8
211       author: cps
212       changes:
213         - createTable:
214             columns:
215               - column:
216                   constraints:
217                     nullable: false
218                   name: schema_node_identifier
219                   type: TEXT
220               - column:
221                   autoIncrement: true
222                   constraints:
223                     nullable: false
224                     primaryKey: true
225                     primaryKeyName: schema_node_pkey
226                   name: id
227                   type: INTEGER
228             tableName: schema_node
229   - changeSet:
230       id: 1-9
231       author: cps
232       changes:
233         - createTable:
234             columns:
235               - column:
236                   constraints:
237                     nullable: false
238                   name: schema_set_id
239                   type: BIGINT
240               - column:
241                   constraints:
242                     nullable: false
243                   name: yang_resource_id
244                   type: BIGINT
245             tableName: schema_set_yang_resources
246   - changeSet:
247       id: 1-10
248       author: cps
249       changes:
250         - createIndex:
251             columns:
252               - column:
253                   name: schema_set_id
254             indexName: FKI_ANCHOR_SCHEMA_SET_ID_FK
255             tableName: anchor
256   - changeSet:
257       id: 1-11
258       author: cps
259       changes:
260         - addUniqueConstraint:
261             columnNames: dataspace_id, name
262             constraintName: anchor_dataspace_id_name_key
263             tableName: anchor
264   - changeSet:
265       id: 1-12
266       author: cps
267       changes:
268         - addForeignKeyConstraint:
269             baseColumnNames: anchor_id
270             baseTableName: fragment
271             constraintName: fragment_anchor_id_fkey
272             deferrable: false
273             initiallyDeferred: false
274             onDelete: NO ACTION
275             onUpdate: NO ACTION
276             referencedColumnNames: id
277             referencedTableName: anchor
278             validate: true
279   - changeSet:
280       id: 1-13
281       author: cps
282       changes:
283         - createIndex:
284             columns:
285               - column:
286                   name: from_fragment_id
287             indexName: FKI_RELATIONS_FROM_ID_FK
288             tableName: relation
289   - changeSet:
290       id: 1-14
291       author: cps
292       changes:
293         - createIndex:
294             columns:
295               - column:
296                   name: to_fragment_id
297             indexName: FKI_RELATIONS_TO_ID_FK
298             tableName: relation
299   - changeSet:
300       id: 1-15
301       author: cps
302       changes:
303         - createIndex:
304             columns:
305               - column:
306                   name: relation_type_id
307             indexName: FKI_RELATION_TYPE_ID_FK
308             tableName: relation
309   - changeSet:
310       id: 1-16
311       author: cps
312       changes:
313         - addPrimaryKey:
314             columnNames: to_fragment_id, from_fragment_id, relation_type_id
315             constraintName: relation_pkey
316             tableName: relation
317   - changeSet:
318       id: 1-17
319       author: cps
320       changes:
321         - createIndex:
322             columns:
323               - column:
324                   name: anchor_id
325             indexName: FKI_FRAGMENT_ANCHOR_ID_FK
326             tableName: fragment
327   - changeSet:
328       id: 1-18
329       author: cps
330       changes:
331         - createIndex:
332             columns:
333               - column:
334                   name: dataspace_id
335             indexName: FKI_FRAGMENT_DATASPACE_ID_FK
336             tableName: fragment
337   - changeSet:
338       id: 1-19
339       author: cps
340       changes:
341         - createIndex:
342             columns:
343               - column:
344                   name: parent_id
345             indexName: FKI_FRAGMENT_PARENT_ID_FK
346             tableName: fragment
347   - changeSet:
348       id: 1-20
349       author: cps
350       changes:
351         - createIndex:
352             columns:
353               - column:
354                   name: schema_node_id
355             indexName: FKI_SCHEMA_NODE_ID_TO_ID
356             tableName: fragment
357   - changeSet:
358       id: 1-21
359       author: cps
360       changes:
361         - createIndex:
362             columns:
363               - column:
364                   name: xpath
365               - column:
366                   name: dataspace_id
367             indexName: UQ_FRAGMENT_XPATH
368             tableName: fragment
369             unique: true
370   - changeSet:
371       id: 1-22
372       author: cps
373       changes:
374         - addUniqueConstraint:
375             columnNames: dataspace_id, anchor_id, xpath
376             constraintName: fragment_dataspace_id_anchor_id_xpath_key
377             tableName: fragment
378   - changeSet:
379       id: 1-23
380       author: cps
381       changes:
382         - addForeignKeyConstraint:
383             baseColumnNames: from_fragment_id
384             baseTableName: relation
385             constraintName: relation_from_fragment_id_fkey
386             deferrable: false
387             initiallyDeferred: false
388             onDelete: NO ACTION
389             onUpdate: NO ACTION
390             referencedColumnNames: id
391             referencedTableName: fragment
392             validate: true
393   - changeSet:
394       id: 1-24
395       author: cps
396       changes:
397         - addForeignKeyConstraint:
398             baseColumnNames: to_fragment_id
399             baseTableName: relation
400             constraintName: relation_to_fragment_id_fkey
401             deferrable: false
402             initiallyDeferred: false
403             onDelete: NO ACTION
404             onUpdate: NO ACTION
405             referencedColumnNames: id
406             referencedTableName: fragment
407             validate: true
408   - changeSet:
409       id: 1-25
410       author: cps
411       changes:
412         - addUniqueConstraint:
413             columnNames: name, dataspace_id
414             constraintName: schema_set_name_dataspace_id_key
415             tableName: schema_set
416   - changeSet:
417       id: 1-26
418       author: cps
419       changes:
420         - addForeignKeyConstraint:
421             baseColumnNames: schema_set_id
422             baseTableName: schema_set_yang_resources
423             constraintName: schema_set_resource
424             deferrable: false
425             initiallyDeferred: false
426             onDelete: CASCADE
427             onUpdate: NO ACTION
428             referencedColumnNames: id
429             referencedTableName: schema_set
430             validate: true
431   - changeSet:
432       id: 1-27
433       author: cps
434       changes:
435         - addUniqueConstraint:
436             columnNames: checksum
437             constraintName: yang_resource_checksum_key
438             tableName: yang_resource
439   - changeSet:
440       id: 1-28
441       author: cps
442       changes:
443         - addUniqueConstraint:
444             columnNames: name
445             constraintName: UQ_NAME
446             tableName: dataspace
447   - changeSet:
448       id: 1-29
449       author: cps
450       changes:
451         - addForeignKeyConstraint:
452             baseColumnNames: dataspace_id
453             baseTableName: fragment
454             constraintName: fragment_dataspace_id_fkey
455             deferrable: false
456             initiallyDeferred: false
457             onDelete: NO ACTION
458             onUpdate: NO ACTION
459             referencedColumnNames: id
460             referencedTableName: dataspace
461             validate: true
462   - changeSet:
463       id: 1-30
464       author: cps
465       changes:
466         - addForeignKeyConstraint:
467             baseColumnNames: dataspace_id
468             baseTableName: schema_set
469             constraintName: schema_set_dataspace
470             deferrable: false
471             initiallyDeferred: false
472             onDelete: CASCADE
473             onUpdate: CASCADE
474             referencedColumnNames: id
475             referencedTableName: dataspace
476             validate: true
477   - changeSet:
478       id: 1-31
479       author: cps
480       changes:
481         - createIndex:
482             columns:
483               - column:
484                   name: schema_node_identifier
485             indexName: PERF_SCHEMA_NODE_SCHEMA_NODE_ID
486             tableName: schema_node
487   - changeSet:
488       id: 1-32
489       author: cps
490       changes:
491         - addForeignKeyConstraint:
492             baseColumnNames: yang_resource_id
493             baseTableName: schema_set_yang_resources
494             constraintName: schema_set_yang_resources_yang_resource_id_fkey
495             deferrable: false
496             initiallyDeferred: false
497             onDelete: NO ACTION
498             onUpdate: NO ACTION
499             referencedColumnNames: id
500             referencedTableName: yang_resource
501             validate: true
502   - changeSet:
503       id: 1-33
504       author: cps
505       changes:
506         - addForeignKeyConstraint:
507             baseColumnNames: dataspace_id
508             baseTableName: anchor
509             constraintName: anchor_dataspace_id_fkey
510             deferrable: false
511             initiallyDeferred: false
512             onDelete: NO ACTION
513             onUpdate: NO ACTION
514             referencedColumnNames: id
515             referencedTableName: dataspace
516             validate: true
517   - changeSet:
518       id: 1-34
519       author: cps
520       changes:
521         - addForeignKeyConstraint:
522             baseColumnNames: schema_set_id
523             baseTableName: anchor
524             constraintName: anchor_schema_set_id_fkey
525             deferrable: false
526             initiallyDeferred: false
527             onDelete: NO ACTION
528             onUpdate: NO ACTION
529             referencedColumnNames: id
530             referencedTableName: schema_set
531             validate: true
532   - changeSet:
533       id: 1-35
534       author: cps
535       changes:
536         - addForeignKeyConstraint:
537             baseColumnNames: relation_type_id
538             baseTableName: relation
539             constraintName: relation_relation_type_id_fkey
540             deferrable: false
541             initiallyDeferred: false
542             onDelete: NO ACTION
543             onUpdate: NO ACTION
544             referencedColumnNames: id
545             referencedTableName: relation_type
546             validate: true
547   - changeSet:
548       id: 1-36
549       author: cps
550       changes:
551         - addForeignKeyConstraint:
552             baseColumnNames: parent_id
553             baseTableName: fragment
554             constraintName: fragment_parent_id_fkey
555             deferrable: false
556             initiallyDeferred: false
557             onDelete: NO ACTION
558             onUpdate: NO ACTION
559             referencedColumnNames: id
560             referencedTableName: fragment
561             validate: true
562   - changeSet:
563       id: 1-37
564       author: cps
565       changes:
566         - addForeignKeyConstraint:
567             baseColumnNames: schema_node_id
568             baseTableName: fragment
569             constraintName: fragment_schema_node_id_fkey
570             deferrable: false
571             initiallyDeferred: false
572             onDelete: NO ACTION
573             onUpdate: NO ACTION
574             referencedColumnNames: id
575             referencedTableName: schema_node
576             validate: true
577   - changeSet:
578       logicalFilePath:  changelog/db/changes/06-delete-not-required-fragment-index.yaml
579       id: 6
580       author: cps
581       comment: Drop unique index for dataspace and xpath on fragment table
582       changes:
583         - dropIndex:
584             indexName: UQ_FRAGMENT_XPATH
585             tableName: fragment
586       rollback:
587         - createIndex:
588             columns:
589               - column:
590                   name: xpath
591               - column:
592                   name: dataspace_id
593             indexName: UQ_FRAGMENT_XPATH
594             tableName: fragment
595             unique: true
596
597   - changeSet:
598       logicalFilePath:  changelog/db/changes/11-add-column-to-yang-resources-table.yaml
599       id: 11
600       label: add-module-name-and-revision-column
601       author: cps
602       changes:
603         - addColumn:
604             tableName: yang_resource
605             columns:
606               - column:
607                   name: module_name
608                   type: TEXT
609               - column:
610                   name: revision
611                   type: TEXT
612   - changeSet:
613       logicalFilePath:  changelog/db/changes/11-add-column-to-yang-resources-table.yaml
614       id: 11.1
615       label: update-previous-data-module-name-and-revision
616       author: cps
617       changes:
618         - sql:
619             sql: update yang_resource set module_name = 'dummy_module_name', revision = '2021-08-04' where module_name is null and revision is null
620       rollback:
621         sql: update yang_resource set module_name = null, revision = null where module_name = 'dummy_module_name' and revision = '2021-08-04'
622   - changeSet:
623       logicalFilePath:  changelog/db/changes/15-rename-column-yang-resource-table.yaml
624       author: cps
625       label: yang-resource-rename-column
626       id: 15
627       changes:
628         - renameColumn:
629             tableName: yang_resource
630             columnDataType: TEXT
631             oldColumnName: name
632             newColumnName: file_name
633       rollback:
634         - sql:
635             sql: alter table yang_resource rename column file_name to name
636   - changeSet:
637       logicalFilePath:  changelog/db/changes/17-add-index-to-schema-set-yang-resources.yaml
638       author: cps
639       id: 17
640       changes:
641         - createIndex:
642             columns:
643               - column:
644                   name: schema_set_id
645             indexName: FKI_SCHEMA_SET_YANG_RESOURCES_SCHEMA_SET_ID_FK
646             tableName: schema_set_yang_resources
647       rollback:
648         - dropIndex:
649             indexName: FKI_SCHEMA_SET_YANG_RESOURCES_SCHEMA_SET_ID_FK
650             tableName: schema_set_yang_resources
651   - changeSet:
652       logicalFilePath:  changelog/db/changes/18-cascade-delete-fragment-children.yaml
653       author: cps
654       id: 18
655       changes:
656         - dropForeignKeyConstraint:
657             baseTableName: fragment
658             constraintName: fragment_parent_id_fkey
659         - addForeignKeyConstraint:
660             baseColumnNames: parent_id
661             baseTableName: fragment
662             constraintName: fragment_parent_id_fkey
663             deferrable: false
664             initiallyDeferred: false
665             onDelete: CASCADE
666             onUpdate: NO ACTION
667             referencedColumnNames: id
668             referencedTableName: fragment
669             validate: true
670       rollback:
671         - dropForeignKeyConstraint:
672             baseTableName: fragment
673             constraintName: fragment_parent_id_fkey
674         - addForeignKeyConstraint:
675             baseColumnNames: parent_id
676             baseTableName: fragment
677             constraintName: fragment_parent_id_fkey
678             deferrable: false
679             initiallyDeferred: false
680             onDelete: NO ACTION
681             onUpdate: NO ACTION
682             referencedColumnNames: id
683             referencedTableName: fragment
684             validate: true
685   - changeSet:
686       logicalFilePath:  changelog/db/changes/19-delete-not-required-dataspace-id-from-fragment.yaml
687       id: 19-1
688       author: cps
689       changes:
690         - dropIndex:
691             indexName: FKI_FRAGMENT_DATASPACE_ID_FK
692             tableName: fragment
693       rollback:
694         - createIndex:
695             columns:
696               - column:
697                   name: dataspace_id
698             indexName: FKI_FRAGMENT_DATASPACE_ID_FK
699             tableName: fragment
700   - changeSet:
701       logicalFilePath: changelog/db/changes/19-delete-not-required-dataspace-id-from-fragment.yaml
702       id: 19-2
703       author: cps
704       changes:
705         - dropUniqueConstraint:
706             constraintName: fragment_dataspace_id_anchor_id_xpath_key
707             tableName: fragment
708         - addUniqueConstraint:
709             columnNames: anchor_id, xpath
710             constraintName: fragment_anchor_id_xpath_key
711             tableName: fragment
712       rollback:
713         - dropUniqueConstraint:
714             constraintName: fragment_anchor_id_xpath_key
715             tableName: fragment
716         - addUniqueConstraint:
717             columnNames: dataspace_id, anchor_id, xpath
718             constraintName: fragment_dataspace_id_anchor_id_xpath_key
719             tableName: fragment
720   - changeSet:
721       logicalFilePath: changelog/db/changes/19-delete-not-required-dataspace-id-from-fragment.yaml
722       id: 19-3
723       author: cps
724       changes:
725         - dropForeignKeyConstraint:
726             baseTableName: fragment
727             constraintName: fragment_dataspace_id_fkey
728       rollback:
729         - addForeignKeyConstraint:
730             baseColumnNames: dataspace_id
731             baseTableName: fragment
732             constraintName: fragment_dataspace_id_fkey
733             deferrable: false
734             initiallyDeferred: false
735             onDelete: NO ACTION
736             onUpdate: NO ACTION
737             referencedColumnNames: id
738             referencedTableName: dataspace
739             validate: true
740   - changeSet:
741       logicalFilePath: changelog/db/changes/19-delete-not-required-dataspace-id-from-fragment.yaml
742       id: 19-4
743       author: cps
744       changes:
745         - dropColumn:
746             columnName: dataspace_id
747             tableName: fragment
748       rollback:
749         - addColumn:
750             tableName: fragment
751             columns:
752               - column:
753                   name: dataspace_id
754                   type: INTEGER
755         - sqlFile:
756             path: changelog/db/changes/19-repopulate-dataspace-id-for-rollback.sql
757         - addNotNullConstraint:
758             tableName: fragment
759             columnName: dataspace_id
760             columnDataType: INTEGER
761
762   - changeSet:
763       logicalFilePath: changelog/db/changes/19-delete-not-required-dataspace-id-from-fragment.yaml
764       id: 19-5
765       author: cps
766       changes:
767         - addNotNullConstraint:
768             tableName: fragment
769             columnName: anchor_id
770             columnDataType: BIGINT
771       rollback:
772         - dropNotNullConstraint:
773             tableName: fragment
774             columnName: anchor_id
775             columnDataType: BIGINT
776   - changeSet:
777       author: cps
778       logicalFilePath: changelog/db/changes/20-change-foreign-key-id-types-to-integer.yaml
779       id: 20
780       changes:
781         - modifyDataType:
782             columnName: dataspace_id
783             newDataType: INTEGER
784             tableName: schema_set
785         - modifyDataType:
786             columnName: schema_set_id
787             newDataType: INTEGER
788             tableName: schema_set_yang_resources
789         - modifyDataType:
790             columnName: yang_resource_id
791             newDataType: INTEGER
792             tableName: schema_set_yang_resources
793       rollback:
794         - modifyDataType:
795             columnName: dataspace_id
796             newDataType: BIGINT
797             tableName: schema_set
798         - modifyDataType:
799             columnName: schema_set_id
800             newDataType: BIGINT
801             tableName: schema_set_yang_resources
802         - modifyDataType:
803             columnName: yang_resource_id
804             newDataType: BIGINT
805             tableName: schema_set_yang_resources
806   - changeSet:
807       logicalFilePath:  changelog/db/changes/21-escape-quotes-in-xpath.yaml
808       id: 21
809       author: cps
810       changes:
811         - sqlFile:
812             path: changelog/db/changes/21-escape-quotes-in-xpath-forward.sql
813       rollback:
814         - sqlFile:
815             path: changelog/db/changes/21-escape-quotes-in-xpath-rollback.sql