liquibasechecksumliquibase-sql

Liquibase - validation failed checksum changed


This is the first version of my changelog.sql:

-- liquibase formatted sql

-- changeset kh:1
CREATE TABLE test_table (test_id INT, test_column VARCHAR(256), PRIMARY KEY (test_id))

--changeset kh:2
INSERT INTO test_table (test_id, test_column) VALUES(3,'saket');

This is an update of my changelog.sql (Added a column in the first changeset):

-- liquibase formatted sql

-- changeset kh:1
CREATE TABLE test_table (test_id INT, test_column VARCHAR(256), test_column2 VARCHAR(256), PRIMARY KEY (test_id))

--changeset kh:2
INSERT INTO test_table (test_id, test_column) VALUES(3,'saket');

I execute a liquibase update with the following command:

docker run --rm -v /changelog:/liquibase/changelog liquibase/liquibase \
--url=jdbc:postgresql://xxxxxxxxxx:5432/postgres \
--changelog-file=changelog.sql --username=xxxx \
--password=xxxx update

I get this error:

Caused by: liquibase.exception.ValidationFailedException: Validation Failed:
     1 changesets check sum
          changelog.sql::1::kh was: 8:46ea95d67274343c559a1c5ddc8ee33 but is now: 8:ab7361c532323a6a32bc79d230a46574

I understand that when running it in a productive environment, it should fail in order not to launch scripts again by mistake, but, in a non-productive environment, how should it work?

I imagine three solutions in a DevOps (NonProd) scenario:

  1. Restore database as the first step and execute changelog for specific version.
  2. For nonprod, ignore the checksum validation
  3. Modify the changelog and add a new changeset with the change.- For my taste, this is the least correct

In a non-production environment, it may be necessary to make changes to SQL until the new functionality is validated. What is the best practice, and is there any other solution?


Solution

  • The checksum error indicates that you are modifying a changeset that has already been executed in the particular database target. Therefore, Liquibase does not understand why you are doing this modification.

    The sql statement "CREATE TABLE test_table" cannot be executed again, so adding the additional column does not make sense.

    If you want to add a column to a table that has already been created, you really only have 2 options:

    1. Drop and recreate the table to include the new column
    2. Alter the table to add the new column

    Option 1 can be acomplished by using Liquibase rollback, followed by modifying the changeset, and then Liquibase update. Option 2 can be accomplished by adding a new changeset.

    Both are 100% valid options.