Search code examples
javaliquibase

Liquibase - How to run a Java code changeset using SQL Format?


With Liquibase XML you can trigger Java code to execute for a change with:

    <customChange class="my.java.Class">
        <param name="id" value="2" />
    </customChange>

How can you trigger a custom change with Liquibase SQL Format?


Solution

  • TL;DR You can't.

    The supported formats for defining a custom change set are:

    1. XML
    <changeSet id="21" author="nvoxland">
      <customChange class="liquibase.change.custom.ExampleCustomTaskChange">
        <param name="helloTo" value="world"/>
      </customChange>
    </changeSet>
    
    1. YAML
    -  changeSet:
         id:  21
         author: nvoxland
         changes:
         -  customChange:  {
    "class": "liquibase.change.custom.ExampleCustomTaskChange",
    "helloTo": "world" }
    
    1. JSON
    {
      "changeSet": {
        "id": "21",
        "author": "nvoxland",
        "changes": [
          {
            "customChange": {
              "class": "liquibase.change.custom.ExampleCustomTaskChange",
              "helloTo": "world"
            }
          }
        ]
      }
    }
    

    Based on https://docs.liquibase.com/change-types/custom-change.html