Liquibase always executing changesets

0

Hello, I have a problem running Liquibase with Maven + Spring Boot. The following occurs:

I have two schemas, schema1 and schema2. In the project, I have 3 native SQL scripts: first create the two schema, then create the tables and third populate the data.

But whenever I make a mvn clean install and then java -jar projeto-x-0.0.1.jar it says in the logs that the schemas already exist. Even if you get the sql that creates the schemas first, the second script (which creates the tables) also gives error.

I would like to know how to do it so that when I upload the project, I would not execute the same changesets that were already executed the first time. (obs: the two tables of liquibase, databasechangelog and databasechangeloglock, are being created in public schema)

OBS : I found the cause: When I first upload, it creates the databasechangelog and databasechangeloglock tables in public. But then when I go up the second time it creates in schema1. Does anyone know how to solve this problem?

    
asked by anonymous 19.02.2018 / 02:38

1 answer

0

I was able to resolve:

I removed the dependencies of maven for Liquibase and added the plugin "Liquibase Maven Plugin"

With this, I set up normally according to the documentation, this way in pom.xml

<plugin>
  <groupId>org.liquibase</groupId>
  <artifactId>liquibase-maven-plugin</artifactId>
  <version>2.0.1</version>

  <configuration>
    <changeLogFile>db.changelog-master.xml</changeLogFile>
    <driver>org.hsqldb.jdbcDriver</driver>
    <url>jdbc:hsqldb:file:teste;shutdown=true</url>
    <username>seuusuario</username>
    <password></password>
    <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
    <verbose>true</verbose>
    <changelogSchemaName>public</changelogSchemaName>
    <defaultSchemaName>seuschema</defaultSchemaName>
  </configuration>
</plugin>

The magic is in the changelogSchemaName and defaultSchemaName attributes. Where the schemaName is where the version control data of Liquibase itself and defaultSchemaName will be the default schema.

Then just run mvn clean package liquibase:update that magic happens.

    
20.02.2018 / 04:46