簡體   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