简体   繁体   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>

I already have a changelog.xml to this table, and I have to update the the table with an extra xml changelog file, will it work?我已经有一个changelog.xml到这个表,我必须用一个额外的xml更新日志文件来更新这个表,它会工作吗?

As far as I understood, you have existing changelog and you want to include some other changelog file.据我了解,您有现有的更改日志,并且您希望包含其他一些更改日志文件。 You can achieve this by adding following entry at the end of the current changelog file:您可以通过在当前更改日志文件的末尾添加以下条目来实现此目的:

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

The root of all Liquibase changes is the changelog file.所有 Liquibase 更改的根源是更改日志文件。 Liquibase uses a changelog to sequentially list all changes made to your database. Liquibase 使用更改日志来顺序列出对数据库所做的所有更改。 Think of it as a ledger.把它想象成一个分类帐。 It is a file that contains a record of all your database changes (changesets).它是一个包含所有数据库更改(变更集)记录的文件。 Liquibase uses this changelog record to audit your database and execute any changes that are not yet applied to your database. Liquibase 使用此更改日志记录来审核您的数据库并执行尚未应用于您的数据库的任何更改。

Please read more about liquibase changelogs here .在此处阅读有关 liquibase 更改日志的更多信息。 From your question, I think you want to apply more than one changes to your DB which means you are planning to have multiple changesets with targeted DB changes.根据您的问题,我认为您希望对数据库应用多个更改,这意味着您计划对多个更改集进行目标数据库更改。 To achieve this you can follow following 2 ways:为此,您可以遵循以下两种方式:

1. Defining multiple changesets inside single changelog file - In this approach you can define multiple changesets in your changelog file itself and all these changes should get executed. 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>

Read more about liquibase changesets here在此处阅读有关 liquibase 变更集的更多信息

2. Including path to external changeset in your parent changelog file - In this approach you can create a separate changeset.xml file with the changes you want to be applied on your DB and just include it in your changelog file like below: 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>

You can also use includeAll to include all your changesets located inside a directory without having to include each changeset specifically.您还可以使用includeAll来包含位于目录中的所有变更集,而不必专门包含每个变更集。 Read more about includeAll here and Read more about include tag here在此处阅读有关includeAll 的更多信息,并在此处阅读有关include 标签的更多信息

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

相关问题 Liquibase:当changelog.xml存在文件时,收到“文件不存在”异常 - Liquibase: receiving “file does not exist” exception when file exists for changelog.xml 如何在不使用 Liquibase 的情况下摆脱与 Liquibase 相关的“找不到变更日志”错误? - How can I get rid of the 'no changelog could be found' error related to Liquibase without using Liquibase? 使用changelog xml作为流输入运行liquibase - Run liquibase with changelog xml as stream input 如何在XML中调用已经随数据库加载的arraylist - How can I call an arraylist that I already have loaded with my database inside the XML 我如何使用jar文件中的Liquibase更改日志 - How do I use a Liquibase changelog which is in jar file 我可以从 liquibase 调用 Java static function 吗? - Can I call a Java static function from liquibase xml? 我可以强制liquibase 3.5.1忽略旧的变更集校验和差异吗? - Can I force liquibase 3.5.1 to ignore legacy changeset checksum differences? 如何使用 Spring Boot 和 Liquibase 变更集 yaml 文件访问系统属性 - how can I access system properties using spring boot and Liquibase changeset yaml file Liquibase - 从数据库更改中更新changelog XML文件 - Liquibase - Update changelog XML file from database changes 如何在 Java 中使用 xPath 正确解析此 XML 文件? - How can I properly parse this XML file with xPath in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM