loading...

mvn Liquibase:updateSql DatabaseException

damcosset profile image Damien Cosset ・3 min read

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!

Discussion

pic
Editor guide
Collapse
rorah profile image
Ronak Rahman

Hi Damien,

I believe it maybe the name of the output file has to include the type of database platform. Could you try changing migration.sql to migration.postgresql.sql

Also, you can get help on our forum (I just randomly checked here, usually don't search dev.to for liquibase issues):
forum.liquibase.org/
or real-time (ish) chat on our Discord channel:
discord.gg/9yBwMtj

Detailed instructions for generatechangelog, maybe it is the same for updatesql:
Running the generatechangelog command

Verify or configure the liquibase.properties file to include your driver class path, database URL, and user authentication (user name/password) information for the database you want to connect to.
Open your CLI and run the following command:

liquibase --changeLogFile=dbchangelog.xml generateChangeLog

Note: For the SQL changelogs, you need to specify the database type in the file name. The command should be the following:

liquibase --changeLogFile=dbchangelog..sql generateChangeLog

Replace with the short name of the targeted database type. These include h2, oracle, postgresql, and mysql.

The generateChangeLog command generates a changelog that contains your objects (represented as changesets) and places the file in the same directory where the command was run.

Hope that helps!

Ronak

Collapse
damcosset profile image
Damien Cosset Author

Thank you Ronak, I'll take a look!

Collapse
rorah profile image
Ronak Rahman

Hah! I hope it works. Once this gets resolved, I would like to understand a little more why your workflow is this way. My users typically just run a liquibase update rather than translate to sql into a file but I acknowledge that Springboot workflows are not my strong suit. :)

Thread Thread
damcosset profile image
Damien Cosset Author

Sure thing! I'll contact you whenever I'll have a chance to look at the issue more deeply. Right now, I managed to make it work.

The problem was with the postgred:offline URL I provided. It used to work, but now it doesn't anymore. I replaced the url with my local postgresql database and it sorta work.

I wouldn't be surprised if my work flow was not correct at all 😄