Unable to generate offline migration script for PostgreSQL database

It appears that this is a bug in the liquibase.database.core.PostgresDatabase class. Most of the other implementations of getConnectionSchemaName() in the Database classes start with a check for an offline connection and return null.

I have submitted a pull request to fix this - https://github.com/liquibase/liquibase/pull/533

Steve Donie
Principal Software Engineer
Datical, Inc. http://www.datical.com/

Hi



I would like to use Liquibase to generate offline SQL migration scripts for one of my projects and have encountered an issue when creating scripts for PostgreSQL databases.

The entry in the plugins section of my POM file is as follows:

org.liquibase

liquibase-maven-plugin

3.4.2

  <execution>

      <id>liquibase-postgresql-offline</id>

      <configuration>

          <changeLogFile>src/main/resources/liquibase/db-changelog-master.xml</changeLogFile>

          <url>offline:postgresql?changeLogFile=${project.build.directory}/liquibase/postgresql/changelog.csv</url>

          <migrationSqlOutputFile>${project.build.directory}/liquibase/postgresql/migrate.sql</migrationSqlOutputFile>

          <outputFileEncoding>UTF-8</outputFileEncoding>

      </configuration>

      <phase>process-resources</phase>

      <goals>

          <goal>updateSQL</goal>

      </goals>

  </execution>
The error returned by Maven is as follows:

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.2:updateSQL (liquibase-postgresql-offline) on project cobalt-database-resource: Execution liquibase-postgresql-offline of goal org.liquibase:liquibase-maven-plugin:3.4.2:updateSQL failed: Failed to get current schema: Cannot execute commands against an offline database -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.2:updateSQL (liquibase-postgresql-offline) on project cobalt-database-resource: Execution liquibase-postgresql-offline of goal org.liquibase:liquibase-maven-plugin:3.4.2:updateSQL failed: Failed to get current schema
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution liquibase-postgresql-offline of goal org.liquibase:liquibase-maven-plugin:3.4.2:updateSQL failed: Failed to get current schema
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:115)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: java.lang.RuntimeException: Failed to get current schema
at liquibase.database.core.PostgresDatabase.getConnectionSchemaName(PostgresDatabase.java:255)
at liquibase.database.AbstractJdbcDatabase.getDefaultSchemaName(AbstractJdbcDatabase.java:302)
at liquibase.changelog.ChangeLogParameters.(ChangeLogParameters.java:54)
at liquibase.Liquibase.(Liquibase.java:104)
at org.liquibase.maven.plugins.AbstractLiquibaseChangeLogMojo.createLiquibase(AbstractLiquibaseChangeLogMojo.java:81)
at org.liquibase.maven.plugins.LiquibaseUpdateSQL.createLiquibase(LiquibaseUpdateSQL.java:56)
at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:360)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
... 20 more
Caused by: liquibase.exception.DatabaseException: Cannot execute commands against an offline database
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:73)
at liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:117)
at liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:128)
at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:136)
at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:151)
at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:146)
at liquibase.database.core.PostgresDatabase.getConnectionSchemaName(PostgresDatabase.java:250)
... 27 more

I'm able to use offline mode to generate migration SQL scripts for other databases without a problem. I'm also able to do an online migration for PostgreSQL, so the problem seems to be unique to PostgreSQL in offline mode.

Is there something different I need to do to generate offline scripts for PostgreSQL?

Kind Regards

Paul