除了@SteveDonie 所说的之外,还有另一种可能的解决方案或混合解决方案。在您的源代码结构中,您存储标准代码和自定义代码。然后,您可以使用 Liquibase 允许您使用的原始 sql 更改日志文件。
所以有一个类似这样的文件夹结构:
DbCode
|
|---Standard
|---Tables
|---employee.sql
|---sale.sql
|---Schemas
|---public.sql
|---Site1
|---Tables
|---site1_specific_table.sql
|---Schemas
|---site1.sql
|---Site2
|---Tables
|---site2_specific_table.sql
|---Schemas
|---site2.sql
在标准文件夹的根文件夹中放置 0_Main.xml。当您使用此文件运行 liquibase 时,它将为标准数据库构建创建升级。但是,如果我们添加自定义站点,我们将获得特定于该站点的升级。这将允许您在标准文件夹下存储常见的或我称之为标准的代码,并在给定站点文件夹下存储任何特定于站点的代码。所以我们将 0_Main.xml 放在 Site1 和 Site2 下。
C:\DbCode\Standard\0_Main.xml 看起来像这样:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<includeAll path="C:/ProjectX/Standard/Schemas"/>
<includeAll path="C:/ProjectX/Standard/Tables"/>
<includeAll path="C:/ProjectX/Standard/ForeignKeys"/>
</databaseChangeLog>
C:\DbCode\Site1\0_Main.xml 看起来像这样:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<includeAll path="C:/ProjectX/Standard/Schemas"/>
<includeAll path="C:/ProjectX/Standard/Tables"/>
<includeAll path="C:/ProjectX/Standard/ForeignKeys"/>
<includeAll path="C:/ProjectX/Site1/Schemas"/>
<includeAll path="C:/ProjectX/Site1/Tables"/>
<includeAll path="C:/ProjectX/Site1/ForeignKeys"/>
</databaseChangeLog>
C:\DbCode\Site2\0_Main.xml 看起来像这样:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<includeAll path="C:/ProjectX/Standard/Schemas"/>
<includeAll path="C:/ProjectX/Standard/Tables"/>
<includeAll path="C:/ProjectX/Standard/ForeignKeys"/>
<includeAll path="C:/ProjectX/Site2/Schemas"/>
<includeAll path="C:/ProjectX/Site2/Tables"/>
<includeAll path="C:/ProjectX/Site2/ForeignKeys"/>
</databaseChangeLog>
通过这些配置,您可以将代码构建为标准版本和/或 Site1 或 Site2 版本。
includeAll 标签告诉 liquibase 进入给定目录并获取所有脚本。因此,通过首先对 Standard 文件夹执行 includeAll,我们将所有标准对象添加到升级中,然后当我们针对它们的文件夹调用 includeAll 时所有站点特定脚本。