在我使用liquibase的所有架构中应用迁移 [英] apply migration in all schema that i have using liquibase

查看:84
本文介绍了在我使用liquibase的所有架构中应用迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此应用程序中使用Spring Boot开发了一个网站,我正在使用体系结构多租户来管理我的数据库.我想使用Liquibase作为数据库迁移工具.问题是当我进行迁移时,新的修改(修改意味着通过向不同的表中添加新列并添加新表)仅适用于架构公开,而不适用于其他sachems,我想要的是,当我执行时迁移,我希望新修改适用于所有sachemsps:我正在使用休眠模式来创建新的sachems

I developed a website using spring boot in this application I'm using architecture multi tenant to manage my database. I want to use Liquibase as a DB migration tool. The problem is that when i do migration the new modification(modification means by add new columns to different tables and also add new tables) is only apply in schema public and doesn't apply on the others sachems , what i want , when i do migration i want the new modification apply on all sachems ps : i'm using hibernate to create new sachems

推荐答案

Liquibase允许对更改日志文件中的属性进行动态替换.我们可以在文件中配置多个属性,然后在需要时使用它们.在您的情况下,我们可以配置属性"schema1","schema2"带有一些值,然后根据需要使用 $ {schema1} $ {schema2} 语法在changelog文件中使用它.

Liquibase allows dynamic substitution of properties in changelog files. We can configure multiple properties inside a file and then use them wherever required. In your case, we can configure properties "schema1", "schema2" with some value and then use it in changelog file using ${schema1} or ${schema2} syntax as per requirement.

在liquibase.properties文件中,我们将按以下方式配置这些属性:

In liquibase.properties file, we will configure these properties as follows:

schema1=ABC
schema2=PQR

Liquibase按以下顺序为已配置的属性分配值或确定其优先级:

Liquibase assigns or prioritizes value for configured property in below order:

  1. 作为传递给您的liquibase运行程序的属性.
  2. 作为JVM系统属性
  3. 作为环境变量
  4. 如果要通过命令行运行liquibase,请作为CLI属性
  5. 在liquibase.properties文件中
  6. 在参数块(DATABASECHANGELOG表的属性元素)中

您可以按照以下示例代码段进行操作:

You can do it as below example code snippet:

1.在架构ABC中的某个表中添加列:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

    <changeSet author="authorName" id="some-unique-id" dbms="${dbType}" context="some-context">
       <sql endDelimiter=";" splitStatements="true" stripComments="true">
            **My SQL query/ transactional logic goes here**
            ALTER TABLE "${schema1}"."TableName" ADD COLUMN COLUMNNAME DATATYPE;
       </sql>
    </changeSet>
    
</databaseChangeLog>

2.在PQR模式中创建表:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

    <changeSet author="authorName" id="some_unique_id" dbms="${dbType}" context="some_context">
        <createTable tableName="TableName" schemaName="${schema2}">
            <column name="id" type="VARCHAR(200)" />
            <column name="name" type="VARCHAR(255)"/>
        </createTable>
    </changeSet>

</databaseChangeLog>

注意:上面的示例使用2个属性(schema1和schema2).您只能使用更多的东西.

Note: above example is using 2 properties (schema1 and schema2). You can use only even more than that.

如果您需要有关创建"liquibase.properties"的帮助,文件,请访问此链接

If you need help with creating "liquibase.properties" file, visit this link

干杯!

这篇关于在我使用liquibase的所有架构中应用迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆