Search code examples
liquibase

is it possible to add additional config in the liquibase config


Im starting to use liquibase for schema management and it works fine but I also have a need to tag certain tables, columns with some additional details so that it can be used by other schema tooling like phi etc. unable to find relevant resources in the liquibase docs

I have shared an example below:

   - changeSet:
      id: 123
      author: itsme
      changes:
        - createTable:
            tableName: clientdata
            containsPhi: true
            columns:
              - column:
                  name: id
                  type: INT
                  constraints:
                    primaryKey: true
                    nullable: false
              - column:
                  name: firstname
                  phi: true
                  type: varchar(50)
                  constraints:
                    primaryKey: true
                    nullable: false

In the above config, liquibase is okay with a 'createTable' having a 'containsPhi' node but its throwing error for 'phi: true' in the 'column' node.

liquibase.parser.core.ParsedNodeException: Unexpected node: phi

Is there any setting allow these unknown nodes? or any other recommendations. thanks in advance.


Solution

  • To answer your question: no, there are no settings to allow unknown nodes.

    Liquibase has rather strict validation for databaseChangeLog files, so anything unexpected is treated as an error.

    Even if some attribute passes initial validation, it will not be recognized and handled by Liquibase, which makes the addition pointless.


    If you are referring to DB comment feature, then you can use remarks attributes in Liquibase changesets.

    Docs for table remarks.

    databaseChangeLog:
    -  changeSet:
        id:  setTableRemarks-example
        author:  liquibase-docs
        changes:
        -  setTableRemarks:
            catalogName:  cat
            remarks:  A String
            schemaName:  public
            tableName:  person
    

    Docs for column remarks.

    databaseChangeLog:
    -  changeSet:
        id:  setColumnRemarks-example
        author:  liquibase-docs
        changes:
        -  setColumnRemarks:
            catalogName:  department
            columnName:  id
            remarks:  A String
            schemaName:  public
            tableName:  person
            columnDataType:  int
    

    Or if you are creating a new table, just add remarks attribute to createTable change.

    - changeSet:
          id: 123
          author: itsme
          changes:
            - createTable:
                tableName: clientdata
                remarks: phi
                columns:
                  - column:
                      name: id
                      type: INT
                      remarks: phi
                      constraints:
                        primaryKey: true
                        nullable: false
    

    You may also use customChange to implement some custom logic.

    Or you may use sql change to execute plain SQL queries.