Home > Enterprise >  Why does liquibase not create the tables but it creates the changelog?
Why does liquibase not create the tables but it creates the changelog?

Time:12-10

I have the following maven config:

    <profile>
      <id>liquibase-default</id>
      <activation>
        <property>
          <name>!updateSQL</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <configuration>
              <changeLogFile>src/main/database/releases.xml</changeLogFile>
              <driver>oracle.jdbc.driver.OracleDriver</driver>
              <url><url></url>
              <username><user></username>
              <password><pw></password>
              <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
            </configuration>
            <executions>
              <execution>
                <phase>process-resources</phase>
                <goals>
                  <goal>changelogSync</goal>
                  <goal>update</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

as soon as this runs on an empty database two tables are created:

  • DATABASECHANGELOG
  • DATABASECHANGELOGLOCK

But the actual tables which should get created are not there. All the create statements are written in the DATABASECHANGELOG as if liquibase created them but they arent created.

How to tell liquibase to create the tables?

CodePudding user response:

Please try (better):

<changeLogFile>database/releases.xml</changeLogFile>

Alternatively:

${project.build.outputDirectory}/database/releases.xml

resp. the full path.

Since:

As of version 1.6.1.0 of the Maven plugin, all files are resolved from the Maven test classpath for the Maven project or an absolute path. This allows your changelog to be present in other Maven artifacts (on the classpath) and to be used to invoke Liquibase on a database.

Ref: https://docs.liquibase.com/tools-integrations/maven/using-liquibase-and-maven-pom-file.html

maven-resources-plugin should do it's (process-resources: filter&copy) job, before liquibase plugin.

If that's not the case by some circumstances (files not in target/classes), we can:

  • order plugin executions via pom (order of appearance).
  • or (just) by doing liquibase at a later <phase/>

CodePudding user response:

I'm not familiar with Maven, but you have two Liquibase command listed in the "goals" section:

changelogSync and update

Since the changelogSync command is listed first, I assume it's going be executed first. This command is going to take all of the changesets listed in your releases.xml changelog and insert them into the databasechangelog table, making it look like Liquibase applied them to your database, even though it actually didn't. So when the update command executes there are no "pending" changesets to be applied to your database.

https://docs.liquibase.com/commands/change-tracking/changelog-sync.html

  • Related