nllsdfx
nllsdfx

Reputation: 940

Postgres database creation with liquibase

I'm trying to create an empty database using liqubase. I use this approach to do this, but the problem is it doesn't work for me.

I use Postgresql 10 and there are my configurations for maven and liqubase:

 <plugin>
          <groupId>org.liquibase</groupId>
          <artifactId>liquibase-maven-plugin</artifactId>
          <version>3.0.5</version>
          <configuration>
             <propertyFile>src/main/resources/liquibase/liquibase.properties</propertyFile>
          </configuration>
          <executions>
              <execution>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>update</goal>
                    </goals>
              </execution>
          </executions>
  </plugin>

And my liqubase.properties:

changeLogFile=src/main/resources/liquibase/db.changelog.xml
driver=org.postgresql.Driver
dropFirst=false
url=jdbc:postgresql://localhost:5432/auth?createDatabaseIfNotExist=true
username=postgres
password=root

The error on mvn clean package is:

org.postgresql.util.PSQLException: FATAL: database "auth" does not exist

Upvotes: 6

Views: 10608

Answers (2)

Randall
Randall

Reputation: 3034

This is slightly beyond the scope of your question, but you could use liquibase against a Docker postgres instance, and per the docker-library's documentation on ENVIRONMENT VARIABLES, set POSTGRES_DB to "auth" (in your case), and it will create the "auth" db when the docker image launches, with which liquibase can then interact.

Upvotes: 4

SteveDonie
SteveDonie

Reputation: 9016

Liquibase will not create a database that does not exist at all. I also imagine that the url parameter ?createDatabaseIfNotExist=true that is referenced in the linked question/answer is probably MySql specific.

Upvotes: 4

Related Questions