You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 19 Next »

Work in progress


Prerequisites

  1. Agree Scheme changes (ie. create proposal page for the required schema change e.g. with proposed yang file) 
    Example: CPS-677: Support 'public' Cm Handle Properties

Build Docker for Postgres

To start an Postgres database instance using docker issue the following command

docker run --name postgres -p 5432:5432 -d -e POSTGRES_DB=cpsdb -e POSTGRES_USER=cps -e POSTGRES_PASSWORD=cps postgres:13.2-alpine


Applying Pending Changes

To apply any changes made to the changelog within CPS, run the following command from the cps-ri directory

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 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. 

Anytime a new change-log YAML is added, it will need to be included in this file for the changes to be applied within CPS

changelog-master.yaml
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 New Tables

To add new tables to tables within CPS using the Liquibase change-log go to the 01-createCPSTables.yaml file.

Under the databaseChangeLog object each change-set is defined with a unique id (Similar to how an array is defined within YAML).

Here the columns are also defined, along with the constraints of a specific column.

Anchor Table
databaseChangeLog:
  - changeSet:
      id: 1-1
      author: cps
      changes:
        - createTable:
            columns:
              - column:
                  autoIncrement: true
                  constraints:
                    nullable: false
                    primaryKey: true
                    primaryKeyName: anchor_pkey
                  name: id
                  type: BIGINT
              - column:
                  name: name
                  type: TEXT
              - column:
                  name: schema_set_id
                  type: INTEGER
              - column:
                  constraints:
                    nullable: false
                  name: dataspace_id
                  type: INTEGER
            tableName: anchor


To add a new table, under the latest change-set add a new change-set, incrementing the ID by one.

The id of the change-set is based on the change-log YAML file number, and the change-set order. Eg: 1-1, 1-2, 2-1, 2-2, 3-1, 3-2 etc.

- changeSet:
    id: 1-38
    author: cps


Define a changes object, all new edits will go under this section. Create a new createTable object, and under here the table name can be defined along with the column information/constraints as stated above.

Test Table Example
  - changeSet:
      id: 1-38
      author: cps
      changes:
        - createTable:
            columns:
              - column:
                  autoIncrement: true
                  constraints:
                    nullable: false
                    primaryKey: true
                    primaryKeyName: test_table_pkey
                  name: id
                  type: INTEGER
              - column:
                  constraints:
                    nullable: false
                  name: column_1
                  type: TEXT
            tableName: test_table


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.

In the following example, I have created a second test table, which will contain a foreign key shared with the primary key of the first test_table.


Test Table With Foreign Key Example
  - changeSet:
      id: 1-39
      author: cps
      changes:
        - createTable:
            columns:
              - column:
                  autoIncrement: true
                  constraints:
                    nullable: false
                    primaryKey: true
                    primaryKeyName: test_table__with_fk_pkey
                  name: test_table_with_fk_id
                  type: INTEGER
              - column:
                  constraints:
                    nullable: false
                  name: column_1
                  type: TEXT
              - column:
                  constraints:
                    nullable: false
                  name: test_table_pk
                  type: INTEGER
            tableName: test_table_with_fk

From the table above we have created a column of type integer called test_table_pk. This is a reference to the primary key within the first test table created above, which will be our foreign key in this table.

Below is the syntax within YAML for creating a foreign key relation between both tables, the base table and column being the table we are creating the constraint on, and the referenced table and column being the table which contains the PK (id) column we are creating our FK relationship with.

Creating Foreign Key Relation Example
  - changeSet:
      id: 1-40
      author: cps
      changes:
        - addForeignKeyConstraint:
            baseColumnNames: test_table_pk
            baseTableName: test_table_with_fk
            constraintName: test_table_with_fk_fkey
            deferrable: false
            initiallyDeferred: false
            onDelete: NO ACTION
            onUpdate: NO ACTION
            referencedColumnNames: id
            referencedTableName: test_table
            validate: true


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.

There is currently no YAML file within CPS specifically for renaming table columns, this example is done under the presumption that a new file has been created for renaming columns as seen by the updated id from the example.


Rename Column within test table
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.

Add Columns within test table
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.

test_table.csv
renamed_column|new_column1|new_column2
test_table_column_name|columnValue|3

Then each table has a specific YAML change-set which loads the CSV using the following syntax.

Load Data into Test Table
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_@*data-of-creation*'

yang_resource@2021-12-13.csv
name|content|checksum
dmi-registry@2021-12-13.yang|"module dmi-registry {

  yang-version 1.1;

  namespace \"org:onap:cps:ncmp\";

  prefix dmi-reg;

  organization \"Nordix Foundation\";

  contact \"rahul.tyagi@est.tech\";

  revision \"2021-12-13\" {
   description
   \"Added new list of public additonal properties for a Cm-Handle which are exposed to clients of the NCMP interface. \";
  }

  container dmi-registry {

    list cm-handles {

      key \"id\";

      leaf id {
        type string;
      }

      leaf dmi-service-name {
        type string;
      }

      leaf dmi-data-service-name {
        type string;
      }

      leaf dmi-model-service-name {
        type string;
      }

      list additional-properties {
        key \"name\";
        leaf name {
          type string;
        }
        leaf value {
          type string;
        }
      }
      list public-additional-properties {
        key \"name\";
        leaf name {
          type string;
        }
        leaf value {
          type string;
        }
      }
    }
  }
}
"|4899c384835ec48194ab5e3837549d32b844e02cfc81e9205234fa36354f3fe4

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

Run the following command to insert a new yang resource INTO THE 

curl --location --request POST 'http://localhost:8080/cps/api/v1/dataspaces/*dataspacename*/schema-sets' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=' --form 'file=*PATH-TO-YANG-FILE*' --form 'schema-set-name='*NAME-OF-SCEHMA-SET-DEFINED-IN-YANG_RESOURCE*'

Rollback


Potential Issues

  • No labels