【问题标题】:How to modify the default execution order of sql script in liquibase?如何修改liquibase中sql脚本的默认执行顺序?
【发布时间】:2020-02-17 11:41:21
【问题描述】:

我正在尝试在 Liquibase 中运行一堆 sql 脚本。但是,默认情况下,liquibase 会按照它们在目录中的顺序执行所有脚本。有什么方法可以改变这些脚本的执行默认执行,即首先通过创建表脚本执行,然后是所有插入脚本。

我的主变更日志文件:

<?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.1.xsd">
    <includeAll path="../migration/" relativeToChangelogFile="true"/>
</databaseChangeLog>

我将所有 sql 脚本放在迁移文件夹中。

【问题讨论】:

    标签: database oracle migration liquibase


    【解决方案1】:

    您不能修改执行顺序。您唯一能做的就是通过重命名来更改 /migration 目录中文件的顺序。

    据我所知,Liquibase 按字母顺序对文件进行排序。

    并且在文件里面Liquibase从上到下一一执行changeSets。

    您可以使用&lt;include&gt; 代替&lt;includeAll&gt;。这样您就可以按您需要的顺序包含 changeLog 文件。

    <?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.1.xsd">
        <include file="../migration/changeLog_3.xml" relativeToChangelogFile="true"/>
        <include file="../migration/changeLog_1.xml" relativeToChangelogFile="true"/>
        <include file="../migration/changeLog_2.xml" relativeToChangelogFile="true"/>
    </databaseChangeLog>
    

    【讨论】:

    • 好答案!当人们使用 标签时,他们应该为他们的 sql 文件定义一个命名方案。我使用过类似的东西:00010_some_description.sql,然后是00020_next_migration.sql。 Liquibase 博客最近对此进行了介绍:liquibase.org/2020/01/plain-SQL.html
    猜你喜欢
    • 2016-11-24
    • 2018-12-07
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    相关资源
    最近更新 更多