繁体   English   中英

如果我已经有一个 changelog.xml,我该如何正确创建一个外部 liquibase-changeSet-xml?

[英]How can i creat properly an external liquibase-changeSet-xml if i already have a changelog.xml?

<?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.9.xsd">

    
    <changeSet id="sameAsOriginalChangelog" author="xy">
        <addColumn tableName="table_to_modify">
            <column name="new_column"
                    type="varchar(255)">
                <constraints nullable="true"/>
            </column>
        </addColumn>
    </changeSet>
</databaseChangeLog>

我已经有一个changelog.xml到这个表,我必须用一个额外的xml更新日志文件来更新这个表,它会工作吗?

据我了解,您有现有的更改日志,并且您希望包含其他一些更改日志文件。 您可以通过在当前更改日志文件的末尾添加以下条目来实现此目的:

<include file="classpath:/path/to/changelog/additional-liquibase-changelog.xml"/>

所有 Liquibase 更改的根源是更改日志文件。 Liquibase 使用更改日志来顺序列出对数据库所做的所有更改。 把它想象成一个分类帐。 它是一个包含所有数据库更改(变更集)记录的文件。 Liquibase 使用此更改日志记录来审核您的数据库并执行尚未应用于您的数据库的任何更改。

在此处阅读有关 liquibase 更改日志的更多信息。 根据您的问题,我认为您希望对数据库应用多个更改,这意味着您计划对多个更改集进行目标数据库更改。 为此,您可以遵循以下两种方式:

1. 在单个变更日志文件中定义多个变更集- 在这种方法中,您可以在变更日志文件本身中定义多个变更集,所有这些变更都应该被执行。

<?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"  
  xmlns:pro="http://www.liquibase.org/xml/ns/pro"
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd
      http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.8.xsd">  
    <changeSet id="1" author="bob">  
        <comment>A sample change log</comment>  
        <createTable/> 
    </changeSet>  
    <changeSet id="2" author="bob" runAlways="true">  
        <alterTable/>  
    </changeSet>  
    <changeSet id="3" author="alice" failOnError="false" dbms="oracle">
        <alterTable/>  
    </changeSet>  
    <changeSet id="4" author="alice" failOnError="false" dbms="!oracle">
        <alterTable/>  
    </changeSet>  

</databaseChangeLog>

在此处阅读有关 liquibase 变更集的更多信息

2. 在您的父变更日志文件中包含外部变更集的路径- 在这种方法中,您可以创建一个单独的changeset.xml文件,其中包含您要应用于数据库的更改,并将其include在您的变更日志文件中,如下所示:

<?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"
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
    <include file="com/example/news/news.changelog.sql"/>
    <include file="com/example/directory/directory.changelog.sql"/>
</databaseChangeLog>

您还可以使用includeAll来包含位于目录中的所有变更集,而不必专门包含每个变更集。 在此处阅读有关includeAll 的更多信息,并在此处阅读有关include 标签的更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM