我可以在现有的数据库上运行liquibase,但我也在尝试自动化数据库的创建。
我使用的是maven插件,配置如下:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.5.0</version>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
</configuration>
<executions>
<execution>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>我的liquibase.properties文件包含以下内容:
driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/mydb?createDatabaseIfNotExist=true
username=postgres
password=mypass
changeLogFile=db.changelog.xml
referenceUsername=postgres
referencePassword=${database.password}根据另一个question的说法,添加URL参数createDatabaseIfNotExist=true应该会在插件更新目标运行时创建数据库。但是,我得到以下错误:
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.0:update (default-cli) on project accommodation: Error setting up or running Liquibase: liquibase.exception.DatabaseException: org.postgresql.util.PSQLException: FATAL: database "mydb" does not exist -> [Help 1]发布于 2016-09-01 00:22:45
通常,如果数据库不存在,Liquibase不会创建该数据库。Liquibase使用JDBC驱动程序与数据库通信,而JDBC没有从头开始创建数据库的API。许多数据库也不允许只使用SQL创建数据库,所以我认为这就是为什么没有这个特性。
Postgres确实有一个创建数据库的SQL命令,所以您可以尝试使用postgres特定的<sql>更改标记-类似于:
<changeset id="createdatabase" author="steve" dbms="postgres">
<sql>CREATE DATABASE sales OWNER salesapp TABLESPACE salesspace</sql>
</changeset>这根本没有经过测试,而且可能不起作用。
https://stackoverflow.com/questions/39246361
复制相似问题