我用我的数据库实体类和 Liquibase 架构编写了一个 Maven 项目 . 我们的想法是能够运行liquibase changelog 并生成定义的模式 . 这部分工作正常,但只适用于 single schema . 我希望能够将 Liquibase 另一个 schemaName 作为参数,以便它在该模式上运行 update ,作为参数接收 .

我知道如何给Liquibase外部 schemaName

<createTable tableName="client" schemaName="${schemaName}">
            <column name="id" type="bigint">
                <constraints primaryKey="true" nullable="false" />
            </column>

并再次编译该架构:

mvn compile liquibase:update -DschemaName=my-schema

问题在于它需要 liquibase.properties 文件中定义的相同 schemaName ,因此这不是真正的参数化 . 我可以给它一个 schemaName 作为属性,但 also need to change in the properties file 与命令行参数匹配 .

liquibase.properties

driver: org.postgresql.Driver
# currentSchema needs to be changed every time --> problem
url: jdbc:postgresql://localhost:5431/my-db?currentSchema=my-schema
username: postgres
password: root

否则,它不会将 databasechangelogdatabasechangeloglock 创建为作为参数给出的模式,从而无法跟踪该模式中的更改 .

pom.xml

<!-- use Liquibase plugin -->
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.5.3</version>
                <configuration>
                    <propertyFile>liquibase.properties</propertyFile>
                    <changeLogFile>db/master.xml</changeLogFile>
                </configuration>
            </plugin>

我想要:

  • 要么 only 将其命名为 schemaName 作为命令行参数

  • only 设置了一些 properties file

肯定 not 这两个地方 . 这怎么办?