...
title | Work in progress |
---|
...
- Agree Schema changes (ie. create proposal page for the required schema change e.g. with proposed yang file)
Example: CPS-677: Support 'public' Cm Handle Properties
Getting Started
The best way to start working with Liquibase change logs is to load the current CPS change logs into Postgress.
Build Docker for Postgres
Note |
---|
These steps are applied first to load the already existing change-logs within CPS. |
...
Code Block | ||
---|---|---|
| ||
mvn compile org.liquibase:liquibase-maven-plugin:4.3.1:update -Dliquibase.url=jdbc:postgresql://localhost:5432/cpsdb -Dliquibase.username=cps -Dliquibase.password=cps -Dliquibase.changeLogFile=src/main/resources/changelog/changelog-master.yaml |
Change-Log Master Order
The change-log will then be updated running the following yaml files in order, based on the changelog-master.yaml file within the cps-ri->src->main->resources->changelog→db.changes directory.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
databaseChangeLog: - include: file: changelog/db/changes/01-createCPSTables.yaml - include: file: changelog/db/changes/02-loadData-dataspace.yaml - include: file: changelog/db/changes/03-loadData-schema-set.yaml - include: file: changelog/db/changes/04-loadData-anchor.yaml - include: file: changelog/db/changes/05-loadData-fragment.yaml - include: file: changelog/db/changes/06-delete-not-required-fragment-index.yaml - include: file: changelog/db/changes/07-update-yang-resource-checksums.yaml - include: file: changelog/db/changes/08-update-yang-resources.yaml - include: file: changelog/db/changes/09-loadData-dmi-registry-schema-set.yaml - include: file: changelog/db/changes/10-loadData-dmi-registry-fragment.yaml - include: file: changelog/db/changes/11-add-column-to-yang-resources-table.yaml |
Adding Changes
Adding New Tables
To add new tables to tables within CPS using the Liquibase change-log go to the 01-createCPSTables.yaml file.
...
Table once created within SqlDeveloper
Adding/Editing Columns
Once the table is created, columns can be added and edited using a similar syntax to above.
Foreign Key Contraints.
To add foreign key constraints, within the 01-createCPSTables.yaml file create a new change-set and increment the change-set id as done above.
...
test table with fk model.
Rename Column
To rename a column use the following syntax, specifying the table and the oldColumnName, along with the new Column Name.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
databaseChangeLog: - changeSet: id: 12-1 author: cps changes: - renameColumn: newColumnName: renamed_column oldColumnName: column_1 tableName: test_table |
Add New Column
To add a column use the following syntax.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
databaseChangeLog: - changeSet: id: 13-1 author: cps changes: - addColumn: tableName: test_table columns: - column: name: new_column1 type: TEXT - column: name: new_column2 type: INTEGER |
Load Data
The data for each table is defined using the CSV files located within cps-ri->resources->changelog->db.changes->data→dmi.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
databaseChangeLog: - changeSet: author: cps label: xnf-data-preload id: 14.1 loadUpdateData: encoding: UTF-8 file: 'changelog/db/changes/data/test_table.csv' onlyUpdate: 'false' primaryKey: 'id' quotchar: '"' separator: '|' tableName: 'test_table' |
test table with data
Loading data for Yang Resource
To load a yang resource, create a new yang resource csv file to load the data (as outlined above) in the following format 'yang_resource_@*date-of-creation*'
...
Note |
---|
Before adding the checksum in the file above, first generate the checksum within the yang_resource table following the step below |
Generating Checksum For New Yang Resource
First copy the content from the CSV file above and create a YANG file locally with it with the format 'dmi-registry@*date-of-creation*'.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
- changeSet: author: cps label: dmi-registry-schema-preload id: 9.7 loadUpdateData: encoding: UTF-8 file: 'changelog/db/changes/data/dmi/yang_resource@2021-12-13.csv' onlyUpdate: 'false' primaryKey: 'id' quotchar: '"' separator: '|' tableName: 'yang_resource' columns: - column: header: name name: name type: STRING - column: header: content name: content type: STRING - column: header: checksum name: checksum type: STRING rollback: - sql: sql: delete from yang_resource where name = 'dmi-registry@2021-12-13.yang' |
Yang Resource Schema Set
Data will also need to be inserted into the yang_resource_schema_set table to create a mapping between the new yang resource and the necessary schema set.
...
Then add the change-set to the relevent relevant change-log YAML file
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
- changeSet: author: cps label: dmi-registry-schema-preload id: 9.8 loadUpdateData: encoding: UTF-8 file: 'changelog/db/changes/data/dmi/schema_set_yang_resources@2021-12-13.csv' quotchar: '"' primaryKey: 'schema_set_id,yang_resource_id' separator: '|' tableName: 'schema_set_yang_resources' usePreparedStatements: true rollback: - sql: sql: > delete from schema_set_yang_resources where schema_set_id = (select id from schema_set where name = 'ncmp-dmi-registry-model') and yang_resource_id = (select id from yang_resource where name = 'dmi-registry@2021-12-23.yang') |
Rollback
As seen above, the rollback tag is included within the change-set in the case that and updates made need to be reverted.
...
Code Block | ||||
---|---|---|---|---|
| ||||
mvn compile org.liquibase:liquibase-maven-plugin:4.3.1:rollback -Dliquibase.rollbackDate=*date-to-rollback-to* -Dliquibase.url=jdbc:postgresql://localhost:5432/cpsdb -Dliquibase.username=cps -Dliquibase.password=cps -Dliquibase.changeLogFile=src/main/resources/changelog/changelog-master.yaml |
Potential Issues
If the following issue arises:
...