Generation of UUID in yaml liquibase script

1k Views Asked by At

I want to convert my liquibase script from this OLD to NEW format. But in new format the uuid_in(md5(random()::text || clock_timestamp()::text)::cstring) function is not working, and it is taking uuid generator as a string. Any ways to solve this?

OLD- 
 changeSet:
    id: fulfillment-seed-data-1
    author: sas
    preConditions:
      onFail: MARK_RAN
      sqlCheck:
        expectedResult: 0
        sql: select count(*) from ${schema}.global_setting;
    changes:
    - sql:
      dbms: PostgreSQL
      splitStatements: true
      stripComments: true
      sql: INSERT INTO ${schema}.global_setting (global_setting_id, spec_nm, app_nm, spec_value_txt, spec_desc) VALUES(uuid_in(md5(random()::text || clock_timestamp()::text)::cstring), 'PROD_DIMENSION_TYPE_ID', 'FULFILLMENT', '', '');

NEW-
changeSet:
    id: fulfillment-seed-data-1
    author: sas
    preConditions:
      - dbms:
          type: PostgreSQL
      - onFail: MARK_RAN
    changes:
    - insert:
        columns:
        - column:
            name: global_setting_id
            value: 
              - uuid_in(md5(random()::text || clock_timestamp()::text)::cstring)
        - column:
            name: spec_nm
            value: PROD_DIMENSION_TYPE_ID
        - column:
            name: app_nm
            value: FULFILLMENT
        - column:
            name: spec_value_txt
            value:
        - column:
            name: spec_desc
            value:
        tableName: global_setting
1

There are 1 best solutions below

0
Mike Olivas On

Can you use valueComputed for the function call that you are trying to use to compute the value for the column? https://docs.liquibase.com/concepts/changelogs/attributes/column.html In the old case you are using straight sql to make your update. In the new format you are modeling the changes so you need to tell Liquibase to execute that function/sp instead to populate the column value.