【问题标题】:Rename Liquibase changelog tables重命名 Liquibase 更改日志表
【发布时间】:2023-04-03 13:31:02
【问题描述】:

我将 Liquibase (v 3.0.7)Spring (v 4.0.0) 一起使用:

<!-- Liquibase configuration -->
<bean id = "liquibase" class = "liquibase.integration.spring.SpringLiquibase">
    <property name = "dataSource" ref = "dataSource" />
    <property name = "changeLog" value = "classpath:database/changelog.xml" />
</bean>

部署 Spring 应用程序后,Liquibase 将创建两个表:databasechangelogdatabasechangeloglock。有没有办法重命名这两个表?

【问题讨论】:

  • 为什么?这些是记录 liquibase 所做工作的表格。更改他们的名称会使您的设置不标准。

标签: database spring liquibase


【解决方案1】:

您可以使用system properties 覆盖默认表名。

【讨论】:

    【解决方案2】:

    或者您可以使用小变通方法在 spring 配置中设置此名称,检查 Java 配置的此答案 - https://stackoverflow.com/a/50644347 或者您可以将其用于 xml 配置

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util"
           xsi:schemaLocation="http://www.springframework.org/schema/beans
                               http://www.springframework.org/schema/beans/spring-beans.xsd
                              http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
    
        <bean id="liquibaseSystemPropsSetter"
              class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
            <property name="targetObject" value="#{@systemProperties}"/>
            <property name="targetMethod" value="putAll"/>
            <property name="arguments">
                <util:properties>
                    <prop key="liquibase.databaseChangeLogTableName">${application.liquibase.change.log.table.name}</prop>
                    <prop key="liquibase.databaseChangeLogLockTableName">${application.liquibase.change.log.lock.table.name}
                    </prop>
                </util:properties>
            </property>
        </bean>
    
        <bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase"
              depends-on="liquibaseSystemPropsSetter"
              p:dataSource-ref="localDataSource"
              p:changeLog="classpath:${application.liquibase.change.log.path}"
              p:shouldRun="${application.liquibase.should.run}"/>
    
    </beans>
    

    【讨论】:

      猜你喜欢
      • 2018-09-24
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 2020-05-14
      • 2021-11-30
      • 2013-09-29
      • 1970-01-01
      • 2013-06-01
      相关资源
      最近更新 更多