Error setting up or running liquibase

I'm trying to make Liquibase-Hibernate work with JHipster, see issue #754 Here is my configuration: org.liquibase liquibase-maven...

Thanks, now my set up almost works! I am still running in this NPE, though:

Caused by: java.lang.NullPointerException
    at liquibase.ext.hibernate.snapshot.PrimaryKeySnapshotGenerator.addTo(PrimaryKeySnapshotGenerator.java:59)
    at liquibase.ext.hibernate.snapshot.HibernateSnapshotGenerator.snapshot(HibernateSnapshotGenerator.java:80)
    at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)
    at liquibase.ext.hibernate.snapshot.HibernateSnapshotGenerator.snapshot(HibernateSnapshotGenerator.java:72)
    at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)
    at liquibase.ext.hibernate.snapshot.HibernateSnapshotGenerator.snapshot(HibernateSnapshotGenerator.java:72)
    at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)
    at liquibase.ext.hibernate.snapshot.HibernateSnapshotGenerator.snapshot(HibernateSnapshotGenerator.java:72)
    at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)
    at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:163)
    at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:241)
    at liquibase.snapshot.DatabaseSnapshot.replaceObject(DatabaseSnapshot.java:263)
    at liquibase.snapshot.DatabaseSnapshot.includeNestedObjects(DatabaseSnapshot.java:195)
    at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:177)
    at liquibase.snapshot.DatabaseSnapshot.init(DatabaseSnapshot.java:60)
    at liquibase.snapshot.DatabaseSnapshot.<init>(DatabaseSnapshot.java:37)
    at liquibase.snapshot.JdbcDatabaseSnapshot.<init>(JdbcDatabaseSnapshot.java:25)
    at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:126)
    at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:119)
    at liquibase.command.DiffCommand.createReferenceSnapshot(DiffCommand.java:190)
    at liquibase.command.DiffCommand.createDiffResult(DiffCommand.java:140)
    at liquibase.command.DiffCommand.run(DiffCommand.java:132)
    at liquibase.command.AbstractCommand.execute(AbstractCommand.java:8)
    ... 32 more

But this is probably not related to this issue anymore. Should I open another issue? Or do you think this is because of some misconfiguration?

Here is my current setup:

            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.4.0-SNAPSHOT</version>
                <configuration>
                    <propertyFile>src/main/resources/config/liquibase/liquibase.properties.generation</propertyFile>
                    <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>${project.artifactId}</artifactId>
                        <version>${project.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.liquibase</groupId>
                        <artifactId>liquibase-core</artifactId>
                        <version>3.4.0-SNAPSHOT</version>
                        <exclusions>
                            <exclusion>
                                <artifactId>jetty-servlet</artifactId>
                                <groupId>org.eclipse.jetty</groupId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate4</artifactId>
                        <version>3.5-SNAPSHOT</version>
                        <exclusions>
                            <exclusion>
                                <artifactId>hibernate-jpa-2.0-api</artifactId>
                                <groupId>org.hibernate.javax.persistence</groupId>
                            </exclusion>
                        </exclusions>
                    </dependency>
                    <dependency>
                        <groupId>org.liquibase.ext</groupId>
                        <artifactId>liquibase-hibernate4</artifactId>
                        <version>3.5-SNAPSHOT</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-context-support</artifactId>
                        <version>${spring.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-orm</artifactId>
                        <version>${spring.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>xml-apis</groupId>
                        <artifactId>xml-apis</artifactId>
                        <version>1.4.01</version>
                    </dependency>
                </dependencies>
            </plugin>
changeLogFile: src/main/resources/config/liquibase/master.xml
#diffChangeLogFile: src/main/resources/config/liquibase/changelog/20150105150500_main_schema.xml
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/project_template
defaultSchema: project_template
username: root
password: root
referenceUrl: hibernate:spring:app.model?dialect=org.hibernate.dialect.MySQL5Dialect
verbose: true
dropFirst: false
logging: debug

All About Changeset Checksums

Updated October 8, 2021

In order to detect changes between what is currently in the changelog vs. what was actually run against the database, Liquibase stores a checksum with each changeset entry in the DATABASECHANGELOG tracking table.

Liquibase uses a checksum to detect if your target database was updated. The checksum is computed after the parameters are applied. For example, let’s say your target database already ran the following changeset:

This changeset adds “my_column” as an “int”. The changelog contains the same “id=1, author=example” changeset as the following changeset:

This changeset adds “my_column” as a “bigint” instead.

Since Liquibase tracks which changesets have run against your target database by the id/author/filepath combination, it sees the updated changeset as “ran” even though your target database has “my_column” as an “int” column rather than the expected “bigint” type.

If you run the “int” changeset against your database and then change it to “bigint” and re-run update, Liquibase will exit with the following error:

This error shows how Liquibase notices that your target database is out of sync with the changelog.

However, not every change to a changeset impacts the checksum. Here are some examples:

  • Reformatting whitespace and linebreaks (except within SQL statements)
  • Changing preconditions
  • Changing contexts
  • Changing labels
  • Adding validCheckSum settings
  • Changing comments (via native xml/yaml comments or using the comment tag)

Troubleshooting checksums

Don’t fear the checksum. It is here to help you add metadata to changesets that have already been run without problems. Checksums are also helpful because they can catch errors early in your pipeline and revert the changeset back to the original version and help you roll forward with a new changeset.

If you do end up with a checksum issue, you have several options to address it.

Revert and roll forward

Using our earlier example above, you can set the type back to “int” and add a new modifyDataType changeset to change the column from “int” to “bigint”. Previous development databases would need to be rebuilt with the correct checksum, but the fact that they didn’t catch the checksum error originally means they are ephemeral and rebuilding is the easier option.

Valid checksum tag

If the revert + roll-forward approach doesn’t work for you, you can use the tag to specify which checksum that you want to accept as valid, even if it’s different than what was stored in the DATABASECHANGELOG table. Use the checksum values from the error message.

Using our example, your final changeset would look like the following:

The type is still “bigint”, but it now has a validCheckSum tag.

Running this changeset against your database which originally ran the “int” version will no longer complain about the checksum error — but it still considers the changeset as “ran”. That means the column will remain an “int”.

If that is okay with you, you can leave it that way. If it’s not okay and you want to update it, you can add an additional modifyDataType changeset from “int” to “bigint” with a “changeSetRan” onFail=MARK_RAN precondition right before the addColumn changest. Doing this will migrate only databases that had already run the changest and leave the rest.

Manually modify

Of course, if it is just a handful of “problem” databases, you can also just manually modify their datatype and be done.

Источник

Liquibase error: 1 change sets check sum #478

Comments

yarmail commented Apr 22, 2021 •

Возможно кому-то покажется полезным, особенно ученикам,
которые вынуждены часто исправлять свои таблицы.
Возможно это следует добавить к работе с Liquibase

Ситуация такая:
В проекте Grabber нужно было обновить таблицу Post.
Я убрал её командой
drop table if exists post cascade;

После этого в скрипте хотел создать таблицу заново (с тем же именем),
но получил ошибку в Maven test такого плана:

. Failed to execute goal org.liquibase:liquibase-maven-plugin
. 1 change sets check sum .

Если я правильно понимаю — есть проблема создавать таблицы с одинаковыми
названиями. Liquibase каждой таблице присваивает уникальный номер (check sum)
и поэтому ругается, когда имена таблиц совпадают, а номера нет.

Возможное решение: перед созданием новой таблицы с похожим именем
выполнить команду в терминале:
mvn liquibase:clearCheckSums
Источник:
https://docs.liquibase.com/tools-integrations/maven/commands/maven-clearchecksums.html

Также возможно для целей обучения, (если кураторы сочтут это необходимым)
имеет смысл поменять настройки Liquibase в pom.
Если я правильно понимаю, это что-то типа такого:
.
groupId org.liquibase groupId
.
goal clearCheckSums goal

The text was updated successfully, but these errors were encountered:

Источник

AppDynamics Community

Click the Start a free trial link to start a 15-day SaaS trial of our product and join our community as a trial user. If you are an existing customer do not start a free trial.

AppDynamics customers and established members should click the sign in button to authenticate.

  • AppDynamics Community
  • Knowledge Base
  • How do I fix a Liquibase validation error during a.
  • Subscribe to RSS Feed
  • Mark as New
  • Mark as Read
  • Bookmark
  • Subscribe
  • Printer Friendly Page
  • Report Inappropriate Content

How do I fix a Liquibase validation error during a EUM Schema update?

  • Article History
  • Subscribe to RSS Feed
  • Mark as New
  • Mark as Read
  • Bookmark
  • Subscribe
  • Printer Friendly Page
  • Report Inappropriate Content

on ‎04-27-2020 12:14 PM — edited on ‎06-05-2020 01:13 PM by Claudia.Landiva r

Resolving an intermittent Liquibase error when upgrading to EUM Server v4.5 from a version lower than 4.4

Problem

As of the 4.5 EUM Server in production, the EUM MySQL database has been moved from the Controller host machine to the EUM Server host machine.

As a result, when upgrading to EUM Server version 4.5 from a version lower than 4.4, t you may see this intermittent error after the database has been imported and during the schema update:

Solution

To resolve this error, log in to the EUM database and run this SQL query:

Then, run the eum-schema command again, using the root user:

For alternate solution, execute these commands:

Источник

Changelog Formats

The changeset tag is a unit of change that Liquibase executes on a database and which is used to group database Liquibase Change Types together. A list of changes created by multiple changeset s are tracked in a changelog .

A changeset is uniquely tagged by both an author and an id attribute s ( author:id ), as well as the changelog file path. The id tag is only used as an identifier, it does not direct the order that changes are run and does not have to be an integer. If you do not know or do not want to save the actual author, use a placeholder value such as UNKNOWN . To execute the changeset , you must include both author and id .

Running the changeset

As Liquibase uses the DATABASECHANGELOG table, it reads the changeset s in order and, for each one, checks the DATABASECHANGELOG table to see if the combination of id/author/filepath has been run.

If it has been run, the changeset will be skipped unless there is a runAlways tag set to true in that changeset . After all the changes in the changeset s are run, Liquibase will insert a new row with the id/author/filepath along with an MD5Sum of the changeset in the DATABASECHANGELOG .

Note: filepath is the path that defines the changelog-file attribute . Even if the same file is referenced with a different path, that is considered a different file unless the logicalFilePath is defined.

Liquibase attempts to execute each changeset in a transaction that is committed at the end, or rolled back if there is an error. Some databases will auto-commit statements which interferes with this transaction setup and could lead to an unexpected database state. Therefore, it is best practice to have just one change per changeset unless there is a group of non-auto-committing changes that you want to apply as a transaction such as inserting data.

Available attribute s

Specifies an alpha-numeric identifier. Required

Note: If there are zeros in the id, it is best practice to put quotes around the id. ie: «1.10» This allows all characters to be retained.

author Specifies the creator of the changeset . Required dbms Specifies the type of a database for which that changeset will be used. When the migration step is running, it checks the database type against this attribute .

Note: For more information about database type names, see Supported databases page.

Also, you can do the following:

  • List multiple databases separated by commas.
  • Specify that a changeset is not applicable to a particular database type by prefixing it with ! .
  • Add the keywords all and none .

runAlways Executes the changeset on every run, even if it has been run before. runOnChange Executes the changeset the first time and each time the changeset has been changed. Contexts Controls whether a changeset is executed depending on runtime settings. Any string can be used for the context name and they are checked case-insensitively. Labels Controls whether a changeset is executed depending on runtime settings. Any string can be used for the label name and they are checked case-insensitively. runInTransaction

Specifies whether the changeset can be ran as a single transaction (if possible). Default value is true .

Warning: If this attribute is set to false and an error occurs part way through running a changeset that contains multiple statements, the Liquibase DATABASECHANGELOG table will be left in an invalid state. Since 1.9

failOnError Defines whether the migration will fail if an error occurs while executing the changeset . Default value is true . objectQuotingStrategy Controls how object names are quoted in the SQL files generated by Liquibase and used in calls to the database. Default value is LEGACY .

  • LEGACY – The default value. Does not quote objects unless the database specifies that they must be quoted, usually including reserved words and names with hyphens. In PostgreSQL databases, mixed-case names will also be quoted.
  • QUOTE_ALL_OBJECTS – Every object gets quoted. For example, person becomes «person».
  • QUOTE_ONLY_RESERVED_WORDS – The same logic as LEGACY , but without mixed-case objects in PostgreSQL databases.

runOrder Overrides the order in the changelog from where the changeset with the runOrder=»first|last» will be run. It is typically used when you want a changeset to be always executed after everything else but don’t want to keep moving it to the end of the changelog . Setting the runOrder to last will automatically move it in the final changeset order.Since 3.5

Note: The runOrder changeset attribute is not supported in formatted SQL changeset s.

created Stores dates, versions, or any other string of value without using remarks (comments) attribute s. Since 3.5 ignore Ignores the changeset from the execution. Since 3.6 logicalFilePath Overrides the file name and path when creating the unique identifier of changeset s. Required when moving or renaming changelog .

Available sub-tags

comment Specifies the description of the changeset . XML comments will provide the same benefit.
preConditions Must be passed before the changeset will be executed. It is typically used for doing a data sanity check before doing something unrecoverable such as a dropTable .Since 1.7

Note: For more information, see Preconditions.

Specifies the database change(s) to run as part of the changeset (Liquibase Change Types). validCheckSum Adds a checksum that is considered valid for this changeset , regardless of what is stored in the database. It is primarily used when you need to change a changeset and don’t want errors thrown on databases on which it has already been run (not a recommended procedure). Special value «1:any» will match to any checksum and will not execute the changeset on ANY change. Since 1.7 rollback Specifies SQL statements or Change Type tags that describe how to rollback the changeset .

The rollback tag

The rollback tag describes how to roll back a change using SQL statements, Change Type s, or a reference to a previous changeset .

Note: For more information about the rollback tag and examples, see Auto Rollback.

changeset checksums

When Liquibase reaches a changeset , it computes a checksum and stores it in the DATABASECHANGELOG table. The value of storing the checksum for Liquibase is to know if something has been changed in the changeset since it was run.

If the changeset has been changed since it was run, Liquibase will exit the migration with an error message like Validation failed: change set check sums was:

    but is now: . This is because Liquibase cannot identify what was changed and the database may be in a state different than what the changelog is expecting. If there was a valid reason for the changeset to be changed and you want to ignore this error, there are two options.

Note: You can also use the clear-checksums command to resolve the checksum error, however, it will clear the entire column of checksums in your DATABASECHANGELOG table.

The manual update of the DATABASECHANGELOG table

The first option is to manually update the DATABASECHANGELOG table so that the row with the corresponding id/author/filepath has a null value for the checksum. You would need to do this for all environments where the changeset has been deployed. The next time you run the Liquibase update command, it will update the checksum value to the new correct value.

The attribute

The second option is to add a element to the changeset . The text contents of the element should contain the old checksum from the error message.

The runOnChange attribute

Checksums are also used in conjunction with the runOnChange changeset attribute . There are times you may not want to add a new changeset because you only need to know about the current version, but you want this change to be applied whenever it is updated. For example, you can do this with stored procedures.

If you copy the entire text of the stored procedure to a new changeset each time you make a change, you will not only end up with a very long changelog , but you will lose the merging and diffing power of your source control. Instead, put the text of the stored procedure in a changeset with a runOnChange=»true» attribute . The stored procedure will be re-created when there is a change to the text of it.

Note: For more information, see runOnChange.

Источник

Damien Cosset

Hey there! I’m running into a problem inside my Spring boot application that is making me go nuts.

Here is the workflow:

  • Inside my Spring Boot application, I’m connecting to two databases.
  • Liquibase gets the differences between the two and generates a XML file as the changelog.
  • Then, I want to run mvn liquibase:updateSql to get the corresponding SQL from the changelog.

This workflow worked just fine until recently. Now, I get the following error:


[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.10.0:updateSQL (default-cli) on project api: 
[ERROR] Error setting up or running Liquibase:
[ERROR] java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 1
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.liquibase:liquibase-maven-plugin:3.10.0:updateSQL (default-cli) on project api: 
Error setting up or running Liquibase:

Caused by: liquibase.exception.DatabaseException: java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 1
    at liquibase.changelog.OfflineChangeLogHistoryService.getRanChangeSets (OfflineChangeLogHistoryService.java:200)
    at liquibase.changelog.AbstractChangeLogHistoryService.upgradeChecksums (AbstractChangeLogHistoryService.java:66)
    at liquibase.Liquibase.checkLiquibaseTables (Liquibase.java:1174)
    at liquibase.Liquibase.update (Liquibase.java:192)
    at liquibase.Liquibase.update (Liquibase.java:268)
    at liquibase.Liquibase.update (Liquibase.java:250)
    at liquibase.Liquibase.update (Liquibase.java:396)
    at org.liquibase.maven.plugins.LiquibaseUpdateSQL.doUpdate (LiquibaseUpdateSQL.java:51)
    at org.liquibase.maven.plugins.AbstractLiquibaseUpdateMojo.performLiquibaseTask (AbstractLiquibaseUpdateMojo.java:30)
    at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute (AbstractLiquibaseMojo.java:401)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

Inside my pom.xml, I have the following:


<dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>${liquibase.version}</version>
        </dependency>

<!-- Some other stuff...-->
<plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>${liquibase.version}</version>
                    <configuration>
                        <!-- For mvn liquibase:updateSQL -->
                        <changeLogFile>src/main/resources/db/scripts/generated/liquibase/changes.xml</changeLogFile>
                        <migrationSqlOutputFile>src/main/resources/db/scripts/generated/liquibase/migration.sql</migrationSqlOutputFile>
                        <url>offline:postgresql</url>
                    </configuration>
                </plugin>

And this is an example of the XML that liquibase generated:

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.9.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd">
    <changeSet author="damien (generated)" id="1593722682680-1">
        <addForeignKeyConstraint baseColumnNames="fk_user_id" baseTableCatalogName="new_version" baseTableName="user_activity" baseTableSchemaName="public" constraintName="fk1v0u4vq1s7h8hcdb12mt1llb3" deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION" referencedColumnNames="id" referencedTableCatalogName="new_version" referencedTableName="api_user" referencedTableSchemaName="public" validate="true"/>
    </changeSet>
    <changeSet author="damien (generated)" id="1593722682680-2">
        <addColumn catalogName="new_version" schemaName="public" tableName="user_activity">
            <column defaultValueComputed="('now'::text)::date" name="created_on" type="timestamp">
                <constraints nullable="false"/>
            </column>
        </addColumn>
    </changeSet>
    <changeSet author="damien (generated)" id="1593722682680-3">
        <addColumn catalogName="new_version" schemaName="public" tableName="api_user">
            <column name="background_image" type="bytea"/>
        </addColumn>
    </changeSet>
    <changeSet author="damien (generated)" id="1593722682680-4">
        <addColumn catalogName="new_version" schemaName="public" tableName="api_user">
            <column defaultValue="NULL::character varying" name="bio" type="varchar(300 BYTE)"/>
        </addColumn>
    </changeSet>
</databaseChangeLog>

I’m using the version 3.6.3 of Liquibase.

I have tried different liquibase versions but I always get the same error.

Do you have any idea what this DatabaseException refers to?

Thank you!

Case/Problem: 

After adding more fields or relationships in an existing Entity using “yo” or “jhipster” command, especially after adding new fields every time I found following error ( this error is for entity named “Article”) :

ERROR 6385 [line-Executor-1] i.g.j.c.liquibase.AsyncSpringLiquibase  : Liquibase could not start correctly, your database is NOT ready: Validation Failed:
1 change sets check sum

classpath:config/liquibase/changelog/20170804104822_added_entity_Article.xml::20170804104822-1::jhipster was: 7:e7525beb71dfb9d0d785af6863df9775 but is now: 7:ffffbdae995f90f61ec10e387855c106

JHipster_Liquibase_Validation_fail

Liquibase validation fails on the Jhipster project run after modify an existing entity.

Cause:

This error means that we manually changed something on the database table which is no longer matches with the changeset defined in the:  20170804104822_added_entity_Article.xml

But what actually happened is, jhipster added additional information as changeset for newly added fields in the 20170804104822_added_entity_Article.xml, which doesn’t match with the existing table in the database.

As an example following information added in20170804104822_added_entity_Article.xml file but in Article Table the field “highlights” was missing when I added a new field named “highlights” in the Article entity:

<addColumn tableName="article">
 <column name="highlights" type="varchar(255)"/>
</addColumn> 

Issue:

To resolve the problem, you may clean databasechangelog table in your database and drop the Article table, and then start your project again. So, the project will create the Article table again from scratch following the changeset 20170804104822_added_entity_Article.xml.

Or you may update the value of MD5SUM field of databasechangelog table for the with the new one in the error (in my case): 7:ffffbdae995f90f61ec10e387855c106. So this changeset will be ignored by the Liquibase. But the problem is, the new field or your changes will not be applied to the table.

In this way, you can by pass the error with the cost of losing all of you data in Article table, or not synchronizing the table with Article class. But obviously, this is not what we want.

Solution: 

Before you start modifying any Entity, I highly recommend using any version control tools like Git, so that you can revert your change if needed. For this particular case, we need to revert changes in 20170804104822_added_entity_Article.xml made by Jhipster code generator. So, from this point, I assume that you have a stable committed point where you have no error on project run.

  • First, update your existing Entity (in my case the entity name is “article”) using “yo” or “jhipster” command (I assume that you know how to do that, this article will not cover that part). When jhipster ask for replace/update the files, make sure you replace/update 20170804104822_added_entity_Article.xml.
  • After modification process complete run : “./mvnw liquibase:diff”, which must create a change log in “config/liquibase/changelog/” folder with a random name. But you may encounter with the following error.
Error setting up or running Liquibase: liquibase.exception.DatabaseException: java.sql.SQLException: Access denied for user ‘root’@’localhost’ (using password: NO) -> [Help 1]
liquibase diff generate error
  • In case you face the error, means you forget database configuration for “liquibase” (don’t be confused with database configuration for the application) in “pom.xml” file. So, go to pom.xml and find the configuration section for liquibase and provide appropriate information for your database.

Modify following section in pom.xml :

<configuration>
      <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
      <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
      <driver>com.mysql.jdbc.Driver</driver>
      <url>jdbc:mysql://localhost:3306/angular4</url>
      <defaultSchemaName>angular4</defaultSchemaName>
      <username>root</username>
      <password>****</password>
      <referenceUrl>hibernate:spring:com.mycompany.myapp.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&amp;hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&amp;hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>
      <verbose>true</verbose>
      <logging>debug</logging>
 </configuration>
  • Now re-run : “./mvnw liquibase:diff”, which must create a change log in “config/liquibase/changelog/” folder with a random name. if you open the file, you must see the changeset that reflects your changes.
  • In case, if you dont see the change reflection on the file, open the 20170804104822_added_entity_Article.xml, copy the additional change and past it in the “<changeset>” tag in the newly created file as below:
 <changeSet author="author name (generated)" id="1504182236727-1">
   <addColumn tableName="article">
     <column name="highlights" type="varchar(255)"/>
   </addColumn>
 </changeSet>
  • Rename it with a meaningful name and add this new file to “master.xml” file.
  • checkout “config/liquibase/changelog/20170821111321_added_entity_<EntityName>.xml” file you go back to original state of the file before modify your entity. So, the checksum will be same as the database.
  • run “./mvnw ” to run the Jhipster project, the database will be automatically synchronized according to the changelog.

Conclusion:

Here I tried to show, how to resolve liquibase conflict error every time we faced while modifying an existing Entity in a jhipster project.

This article is written based on my personl experience. If you think there are other better way to do this, please feel free to write your opinion in the comments section.

Эй, там! Я столкнулся с проблемой в своем приложении Spring boot, которая сводит меня с ума.

Вот рабочий процесс:

  • В моем приложении Spring Boot я подключаюсь к двум базам данных.
  • Liquibase получает различия между ними и создает XML-файл в качестве списка изменений.
  • Затем я хочу запустить mvn liquibase:updatesql , чтобы получить соответствующий SQL из списка изменений.

Этот рабочий процесс работал просто отлично до недавнего времени. Теперь я получаю следующую ошибку:

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.10.0:updateSQL (default-cli) on project api: 
[ERROR] Error setting up or running Liquibase:
[ERROR] java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 1
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.liquibase:liquibase-maven-plugin:3.10.0:updateSQL (default-cli) on project api: 
Error setting up or running Liquibase:

Caused by: liquibase.exception.DatabaseException: java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 1
    at liquibase.changelog.OfflineChangeLogHistoryService.getRanChangeSets (OfflineChangeLogHistoryService.java:200)
    at liquibase.changelog.AbstractChangeLogHistoryService.upgradeChecksums (AbstractChangeLogHistoryService.java:66)
    at liquibase.Liquibase.checkLiquibaseTables (Liquibase.java:1174)
    at liquibase.Liquibase.update (Liquibase.java:192)
    at liquibase.Liquibase.update (Liquibase.java:268)
    at liquibase.Liquibase.update (Liquibase.java:250)
    at liquibase.Liquibase.update (Liquibase.java:396)
    at org.liquibase.maven.plugins.LiquibaseUpdateSQL.doUpdate (LiquibaseUpdateSQL.java:51)
    at org.liquibase.maven.plugins.AbstractLiquibaseUpdateMojo.performLiquibaseTask (AbstractLiquibaseUpdateMojo.java:30)
    at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute (AbstractLiquibaseMojo.java:401)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

Внутри моего pom.xml, У меня есть следующее:

            org.liquibase
            liquibase-maven-plugin
            ${liquibase.version}
        



                    org.liquibase
                    liquibase-maven-plugin
                    ${liquibase.version}
                    
                        
                        src/main/resources/db/scripts/generated/liquibase/changes.xml
                        src/main/resources/db/scripts/generated/liquibase/migration.sql
                        offline:postgresql
                    
                

И это пример XML, сгенерированного liquibase:

Я использую версию 3.6.3 Liquibase.

Я пробовал разные версии liquibase но я всегда получаю одну и ту же ошибку.

У вас есть какие-либо идеи о том, к чему относится это исключение DatabaseException?

Спасибо!

Оригинал: “https://dev.to/damcosset/mvn-liquibase-updatesql-databaseexception-4l40”


  • Метки


    databaseexception, liquibase, problem, spring

Понравилась статья? Поделить с друзьями:
  • Error setting parameters from dcb com port toolkit
  • Error spell not found enable eldencounter esp
  • Error setting new values common errors
  • Error setting mtrr invalid argument 22
  • Error setting monitor mode on wlan0