liquibase icon indicating copy to clipboard operation
liquibase copied to clipboard

validation don't report an invalid yml

Open ramarro123 opened this issue 1 year ago • 3 comments

Search first

  • [X] I searched and no similar issues were found

Description

if i run validate agains a wrong yml file i got success, and so executing the update. basically the creation of a index with empty column (due to wrong yml) result in a confusing output, as the script got exitcode = 0 but no index is created

Steps To Reproduce

use this changeset

databaseChangeLog:
  - changeSet:
      runAlways: true
      id: fabrickspid-001
      author: gbs05304
      changes:
        - createIndex:
            indexName: SPID_WORKFLOWS_IDX_CREATED_DATETIME
            tableName: SPID_WORKFLOWS
            columns:
              - CREATED_DATETIME
        - createIndex:
            indexName: SPID_WORKFLOWS_IDX_COMPLETED_DATETIME
            tableName: SPID_WORKFLOWS
            columns:
              - COMPLETED_DATE_TIME
        - createIndex:
            indexName: SPID_WORKFLOWS_IDX_STATUS
            tableName: SPID_WORKFLOWS
            columns:
              - STATUS

Expected/Desired Behavior

fail during validation

Liquibase Version

Liquibase Open Source 4.25.1 by Liquibase

Database Vendor & Version

oracle 19c

Liquibase Integration

cli

Liquibase Extensions

none

OS and/or Infrastructure Type/Provider

ubuntu

Additional Context

No response

Are you willing to submit a PR?

  • [ ] I'm willing to submit a PR (Thank you!)

ramarro123 avatar Feb 01 '24 13:02 ramarro123

Hi @ramarro123 I ran liquibase validate with the changelog file you've provided, and this was the output:

Starting Liquibase at 12:06:52 (version 4.25.1 #690 built at 2023-12-18 16:29+0000)
Liquibase Version: 4.25.1
Liquibase Open Source 4.25.1 by Liquibase
ERROR: Exception Details
ERROR: Exception Primary Class:  ValidationFailedException
ERROR: Exception Primary Reason: Validation Failed:
     3 changes have validation failures
          column 'name' is required for all columns in an index, changelog.yml::fabrickspid-001::gbs05304
          column 'name' is required for all columns in an index, changelog.yml::fabrickspid-001::gbs05304
          column 'name' is required for all columns in an index, changelog.yml::fabrickspid-001::gbs05304

ERROR: Exception Primary Source: 4.25.1

Unexpected error running Liquibase: Validation Failed:
     3 changes have validation failures
          column 'name' is required for all columns in an index, changelog.yml::fabrickspid-001::gbs05304
          column 'name' is required for all columns in an index, changelog.yml::fabrickspid-001::gbs05304
          column 'name' is required for all columns in an index, changelog.yml::fabrickspid-001::gbs05304

For more information, please use the --log-level flag

Running liquibase update gets the same results.

Could you check if you're using onValidationFail: MARK_RAN? This would explain the behaviour.

Otherwise, could you send the error output?

Thank you, Tatiana

tati-qalified avatar Feb 14 '24 15:02 tati-qalified

Hello @tati-qalified,

Here is an example of an invalid yaml (addForeignKeyConstraint inside columns) passing validate:

databaseChangeLog:
  - changeSet:
      id: 1
      author: me
      changes:
        - createTable:
            tableName: table
            columns:
              - column:
                  name: id
                  type: BIGINT
              - column:
                  name: other_id
                  type: BIGINT
              - addForeignKeyConstraint:
                  constraintName: fk
                  baseTableName: table
                  baseColumnNames: other_id
                  referencedTableName: other_table
                  referencedColumnNames: id

Note that the same invalid changelog in json format also passes validate:

{
  "databaseChangeLog": [
    {
      "changeSet": {
        "id": "1",
        "author": "me",
        "changes": [
          {
            "createTable": {
              "tableName": "some_table",
              "columns": [
                {
                  "column": {
                    "name": "id",
                    "type": "BIGINT"
                  }
                },
                {
                  "column": {
                    "name": "other_id",
                    "type": "BIGINT"
                  }
                },
                {
                  "addForeignKeyConstraint": {
                    "constraintName": "FK",
                    "baseTableName": "some_table",
                    "baseColumnNames": "other_id",
                    "referencedTableName": "some_other_table",
                    "referencedColumnNames": "id"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}

But this variant (different column declaration) fails with the error below:

{
  "databaseChangeLog": [
    {
      "changeSet": {
        "id": "1",
        "author": "me",
        "changes": [
          {
            "createTable": {
              "tableName": "some_table",
              "columns": [
                {
                  "name": "id",
                  "type": "BIGINT"
                },
                {
                  "name": "other_id",
                  "type": "BIGINT"
                },
                {
                  "addForeignKeyConstraint": {
                    "constraintName": "FK",
                    "baseTableName": "some_table",
                    "baseColumnNames": "other_id",
                    "referencedTableName": "some_other_table",
                    "referencedColumnNames": "id"
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}
liquibase.exception.ChangeLogParseException: Error parsing db.changelog-master.json : Unexpected node: addForeignKeyConstraint

Should I open another issue for this ?

vtheuer avatar Feb 21 '24 10:02 vtheuer

@vtheuer this is a different issue, as it's not exclusive to the yml format. It's a good catch - the validator doesn't detect new changes if they're wrongly placed inside a columns list. This is true for yml and json formats. "Columns" is the only nested tag currently, so it can only be reproduced in a list of columns.

Here's the scenario more graphically described:

 "changeSet": {
   "id": "1",
   "author": "me",
   "changes": [
     {
       "createTable": {
         "tableName": "some_table",
         "columns": [
           {
             "column": {
               "name": "id",
               "type": "BIGINT"
             }
           },
           {
             "column": {
               "name": "other_id",
               "type": "BIGINT"
             }
           },
           {
             "anotherChangeType: {
                ( . . . )
                 ## this should not go here, but it won't be detected by the validator
             }
           }
         ]
       }
     }
   ]
 }

Regarding the second json changelog you've provided (the one that fails), it doesn't trigger the bug because the columns aren't being created correctly. Removing the "column": { ... } segment will make the code fail. The parser won't recognise the list of elements as columns, so the other change type won't be ignored.

I'd recommend you create a new ticket using your code and this information.

Thank you, Tatiana

tati-qalified avatar Feb 21 '24 17:02 tati-qalified