java - 是否可以将表名作为 liquibase 变更集中的参数传递?

标签 java spring hibernate architecture liquibase

I am excuting liquibase chnageset when spring application starts

<changeSet author="kbatra" id="1.2">
        <createTable schemaName="public" tableName="table_a">
            <column name="id" autoIncrement="true" type="BIGINT">
                <constraints primaryKey="true" />
            </column>
            <column name="first_name" type="varchar(255)" />
            <column name="last_name" type="varchar(255)" />
            <column name="username" type="varchar(255)">
                <constraints unique="true" />
            </column>
            <column name="password" type="varchar(1000)" />
            <column name="email" type="varchar(255)" />
        </createTable>
    </changeSet>

Now what i want is i want to execute same changeSet but with the different table name is it possible to pass the table name in liquibase as an argument through spring? Is there any other to acheive this same scenario?

I am working on one module of spring hibernate application where i have to generate same sql schema structure but with different table name at run time as per the users requirement if this is not possible through liquibase then how can i acheive this scenario can anyone please help me to design architecture for this module?

最佳答案

您需要在变更集中使用可替换参数,然后在部署变更集时设置这些参数。您的变更集可能如下所示:

<changeSet author="kbatra" id="1.2">
        <createTable schemaName="public" tableName="${USER_TABLE_NAME}">
            <column name="id" autoIncrement="true" type="BIGINT">
                <constraints primaryKey="true" />
            </column>
            <column name="first_name" type="varchar(255)" />
            <column name="last_name" type="varchar(255)" />
            <column name="username" type="varchar(255)">
                <constraints unique="true" />
            </column>
            <column name="password" type="varchar(1000)" />
            <column name="email" type="varchar(255)" />
        </createTable>
    </changeSet>

然后,当您运行 liquibase update 命令(该命令在应用程序启动时运行)时,您需要设置 USER_TABLE_NAME 的值。

关于java - 是否可以将表名作为 liquibase 变更集中的参数传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44984333/

相关文章:

java - ANTLR解析后生成字符串列表的哈希集

java - 为什么 Java 不接受我的 Generic LinkedList,却接受它自己的 LinkedList?

java - 用户输入长度的异常处理

java - 在 Spring Boot + Spring Integration 应用程序中加密邮件密码

java - 使用@PropertySource配置Spring属性

java - 如何关闭 hibernate 工具数据库连接

java - java如何在没有递归的情况下创建具有相同类型子对象的对象?

java - 将 Spring Boot 1.3.2 升级到 1.4.1 后,Hibernate hbm2ddl (ddl-auto) 失败

java - 删除实体时违反约束

mysql - 如何在hql中使用字符串左函数