首页 文章

Liquibase格式化SQL更改日志和多个文件

提问于
浏览
0

我们开始在spring-boot上使用liquibase进行应用 . 其中一个要求使用普通的sql来进行liquibase . 我们有许多用于初始化数据库的sql文件 . 我查看文档https://www.liquibase.org/documentation/sql_format.html但未找到信息如何创建更改日志sql文件的层次结构 . Spring引导属性 liquibase.change-log 等待单个文件 . 我试图通过 ,; 分隔文件名所有时候从spring-boot得到错误找不到更改日志位置...所以我的问题:
How can i declare execution of another file or files in "sql format"??
像xml等价物:
<include file="second_changelog.sql"/>
<include file="third_changelog.sql"/>

没有工作的例子 first_changelog.sql
--liquibase formatted sql --changeset author_1:1 UPDATE [dbo].[customers] SET name='HD_1' WHERE id = '11'; --import file=second_changelog.sql --import file=third_changelog.sql

PS . 请不要建议xml,因为我只需要SQL

3 回答

  • 2

    您可以使用一个XML文件,其中包含对plain sql的多个引用(有关详细信息,请参阅https://www.liquibase.org/documentation/changes/sql_file.html

    例:

    <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.3.xsd">
    
        <changeSet id="init" author="author">
            <sqlFile encoding="utf8" path="first_changelog.sql"/>
            <sqlFile encoding="utf8" path="second_changelog.sql"/>
        </changeSet>
    
  • 0

    所以,

    看起来您不想使用一个大的格式化SQL更改日志,其中每个更改集都写在文件中 . 相反,如果您想要指向单独的SQL文件(使用纯SQL),则需要一个只触及一次的更改日志,如下所示:

    <changeLog><includeAll path="/path/to/your/sql/directory"></changeLog>
    

    使用 includeAll 告诉Liquibase将您指向的目录中的所有SQL文件拉入,就像它们是单独的changeSet一样 . 见:http://www.liquibase.org/2015/09/liquibase-without-changelogs.html

    P.S:根据你的项目,你可能想看看Datical - 它's a commercial solution that'的建成对Liquibase的顶部,使这一切都轻松了许多 . 您只需要将SQL文件签入到源代码控制中,而Datical有一个代码打包器,可以验证并生成数据库更改的不可变工件 . 您可以完全放弃管理changeLog的业务 .

  • 2

    功能请求仍处于打开状态,分辨率为"No plans yet"请查看以下链接以获取更多讨论:http://forum.liquibase.org/topic/can-we-include-a-file-in-rollback

    Jira中的功能请求ID:https://liquibase.jira.com/browse/CORE-1637

相关问题