使用faker.js新增数据触发Liquibase校验失败问题咨询
I built a monolithic JHipster 6.1.2 app using H2 as the dev database, created a simple Book entity, and generated 10 sample records with faker.js. After adding one more record to the data.csv file, I hit a Liquibase validation error:
2019-06-28 21:59:48.395 ERROR 16399 --- [ paging-task-1] i.g.j.c.liquibase.AsyncSpringLiquibase : Liquibase could not start correctly, your database is NOT ready: Validation Failed: 1 change sets check sum config/liquibase/changelog/20190628133935_added_entity_Book.xml::20190628133935-1-data::jhipster was: 8:ee6d55c24ca401dedb5c3a420721517b but is now: 8:cbad83788edd5ca52ce6bbe66744f473
liquibase.exception.ValidationFailedException: Validation Failed: 1 change sets check sum config/liquibase/changelog/20190628133935_added_entity_Book.xml::20190628133935-1-data::jhipster was: 8:ee6d55c24ca401dedb5c3a420721517b but is now: 8:cbad83788edd5ca52ce6bbe66744f473
at liquibase.changelog.DatabaseChangeLog.validate(DatabaseChangeLog.java:276)
at liquibase.Liquibase.update(Liquibase.java:198)
at liquibase.Liquibase.update(Liquibase.java:179)
at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:353)
at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:305)
at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:119)
at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.lambda$afterPropertiesSet$0(AsyncSpringLiquibase.java:94)
at io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable$1(ExceptionHandlingAsyncTaskExecutor.java:78)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
App Config (.yo-rc.json):
{ "generator-jhipster": { "promptValues": { "packageName": "io.goovy.sampleapp" }, "jhipsterVersion": "6.1.2", "applicationType": "monolith", "baseName": "paging", "packageName": "io.goovy.sampleapp", "packageFolder": "io/goovy/sampleapp", "serverPort": "8080", "authenticationType": "jwt", "cacheProvider": "ehcache", "enableHibernateCache": true, "websocket": false, "databaseType": "sql", "devDatabaseType": "h2Disk", "prodDatabaseType": "mysql", "searchEngine": false, "messageBroker": false, "serviceDiscoveryType": false, "buildTool": "maven", "enableSwaggerCodegen": false, "jwtSecretKey": "NDljY2EyOGMxZjNiNmEyNzk0ODc2MTM2OWIwZTQwNjY1MDRkYWRkNzdmOTE0N2M1NThlOWUwNzc5MDE0MDIwNWQ2OTI1ODU5NTk3YWQzNzRlMDc5MTQ2NTkyYWY4ZDllMTBhNzEyNDU5NWE4ZTIwNDg2MWMzNmQwNTE4OWE5MDk=", "useSass": true, "clientPackageManager": "npm", "clientFramework": "angularX", "clientTheme": "darkly", "clientThemeVariant": "dark", "testFrameworks": [], "jhiPrefix": "jhi", "entitySuffix": "", "dtoSuffix": "DTO", "otherModules": [], "enableTranslation": false } }
Book Entity Config:
{ "fluentMethods": true, "clientRootFolder": "", "relationships": [], "fields": [ { "fieldName": "name", "fieldType": "String" }, { "fieldName": "author", "fieldType": "String" }, { "fieldName": "release", "fieldType": "LocalDate" } ], "changelogDate": "20190628133935", "dto": "mapstruct", "searchEngine": false, "service": "serviceImpl", "entityTableName": "book", "databaseType": "sql", "jpaMetamodelFiltering": true, "pagination": "pagination" }
What's the best practice to resolve this issue?
First, let's break down the root cause: Liquibase calculates a unique checksum for every change set to ensure it hasn't been altered after execution. When you edited the data.csv file referenced by your Book entity's change set, the checksum changed—Liquibase interprets this as a potential tampering risk, hence the validation error.
Here are the recommended approaches tailored to different environments:
1. Reset Checksum (Development Environment Only)
If you're working in a dev setup where test data changes frequently, this is the fastest fix:
- Run the Maven Liquibase command to clear existing checksum records from your database:
mvn liquibase:clearCheckSums - Restart your app. Liquibase will recalculate the checksum for the modified change set and store the new value in the database.
Important: Never use this in production—modifying existing change sets breaks the integrity of your database version history.
2. Create a New Change Set (Production & Long-Term Dev Best Practice)
For any environment where you need to maintain a traceable, unaltered database change history, always add new data via a fresh change set instead of modifying existing ones:
- Create a new changelog file in
src/main/resources/config/liquibase/changelog, e.g.,20190628221500_add_additional_book.xml - Add a change set to insert your new book data. Use
<insert>for a single record, or<loadData>if you want to add multiple entries via a new CSV:<?xml version="1.0" encoding="UTF-8"?> <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd"> <changeSet id="20190628221500-1" author="jhipster"> <insert tableName="book"> <column name="id" valueSequenceNext="book_seq"/> <column name="name" value="New Book Title"/> <column name="author" value="New Author"/> <column name="release" valueDate="2024-01-01"/> <column name="created_by" value="system"/> <column name="created_date" valueDate="${now}"/> </insert> </changeSet> </databaseChangeLog> - Reference this new file in your
master.xmlso Liquibase runs it on startup:<include file="config/liquibase/changelog/20190628221500_add_additional_book.xml"/>
This approach preserves the original change set's integrity and keeps your database history fully auditable.
3. Disable Checksum Validation (Temporary, Not Recommended)
If you need a quick one-off workaround for testing, you can disable Liquibase's checksum validation in your dev config:
- Open
src/main/resources/config/application-dev.ymland add:liquibase: validate-on-migrate: false
Warning: This turns off all checksum checks, so Liquibase won't alert you if any change sets are accidentally modified. Revert this setting as soon as you're done testing.
Bonus: Better Dev Workflow for Test Data
To avoid this issue entirely in development, consider loading test data outside of Liquibase:
- Create a
CommandLineRunnerbean (active only in the dev profile) that inserts test data on app startup - Use custom scripts or JHipster's built-in test data generators instead of modifying Liquibase-managed CSV files
This lets you tweak test data freely without triggering Liquibase checksum errors.
内容的提问来源于stack exchange,提问作者Gerald

