使用Liquibase创建Postgres数据库

6
我正在尝试使用liqubase创建一个空数据库。我使用this方法来实现,但问题是它对我不起作用。
我使用的是Postgresql 10,并且这是我的maven和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>

以及我的 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

mvn clean package出现的错误是:

org.postgresql.util.PSQLException: 致命错误:数据库“auth”不存在

2个回答

5
Liquibase不会创建完全不存在的数据库。我认为在链接的问题/答案中引用的url参数?createDatabaseIfNotExist=true可能是针对MySql特定的。

3
这稍微超出了你的问题范围,但你可以在一个Docker PostgreSQL 实例上使用Liquibase,并根据docker-library的环境变量文档,将POSTGRES_DB设置为"auth"(在你的情况下),当Docker镜像启动时,它会创建名为"auth"的数据库,然后Liquibase可以与之交互。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接