所有 Liquibase 更改的根源是更改日志文件。液体碱 使用变更日志按顺序列出对您所做的所有更改 数据库。把它想象成一个分类账。这是一个包含记录的文件 所有数据库更改(更改集)。 Liquibase 使用这个 更改日志记录来审核您的数据库并执行任何更改 尚未应用到您的数据库。
请在此处阅读有关 liquibase 变更日志的更多信息。 根据您的问题,我认为您希望对数据库应用多个更改,这意味着您计划拥有多个具有目标数据库更改的变更集。要实现这一目标,您可以按照以下 2 种方式进行:
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 tag 这里
据我了解,您有现有的变更日志,并且您想包含一些其他变更日志文件。您可以通过在当前变更日志文件的末尾添加以下条目来实现此目的:
<include file="classpath:/path/to/changelog/additional-liquibase-changelog.xml"/>