Mic*_*tti 5 java mysql database-migration liquibase
除了组织您的变更日志外,我几乎同意Liquibase最佳实践中的每个字眼
我要实现两个主要目标:
1)在application-7.0.0上部署:
if not exists database 'app-db'
create database 'app-db' using database-7.0.0.ddl
sync database 'app-db' with changelog-7.0.0.xml
else
update database 'app-db' with changelog-7.0.0.xml
Run Code Online (Sandbox Code Playgroud)
2)在application-7.0.0版本上:
for each X : version of application (except 7.0.0)
create database 'test-source' using database-X.0.0.ddl
sync database 'test-source' with changelog-X.0.0.xml
update database 'test-source' with changelog-7.0.0.xml
create database 'test-target' using database-7.0.0.ddl
sync database 'test-target' with changelog-7.0.0.xml
diff databases 'test-target' with 'test-source'
if are not equals
throw ERROR
Run Code Online (Sandbox Code Playgroud)
我知道这有点多余,但是我想再次确定,也许您可以说服我(我希望如此),这是没有必要的。
对于第一个目标,使用主从策略来组织变更日志就足够了,但是对于第二个目标,则还不够,因为我没有每个版本的主文件。
所以我想出了一个新的策略:

每个changelog.xml构建如下:
<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.1.xsd">
<include file="../2.0.0/changelog.xml"/>
<changeSet author="Michele" id="3.0.0-1">
<renameColumn tableName="PERSON" oldColumnName="NAME" newColumnName="FIRSTNAME" columnDataType="VARCHAR(255)"/>
</changeSet>
<changeSet author="Michele" id="3.0.0-2" >
<addColumn tableName="PERSON">
<column name="LASTNAME" type="VARCHAR(255)"/>
</addColumn>
</changeSet>
</databaseChangeLog>
Run Code Online (Sandbox Code Playgroud)
通过这种递归布局,每个变更日志文件都可以与同步/更新一起独立使用。
您看到不利的一面还是有更好的策略?
我目前正在使用JPA 2.1(eclipselink 2.5.0),MySQL 5.7,Liquibase 3.1.0,maven 3(和glassfish 4.0)
如果每个版本的变更日志都包含对先前版本变更日志的引用,那么您所拥有的内容在逻辑上与包含每个版本的主变更日志相同。Liquibase 将嵌套的变更日志展平为单个变更集的平面列表,然后按顺序执行每个变更日志。
对于您的模型,您必须更改为每个新版本运行“更新”的changelog.xml 文件,但除此之外它的工作原理相同。
我不确定您的“使用 *.ddl 创建数据库”和“同步数据库”步骤的作用。通常,您只需对数据库运行 liquibase update 命令,liquibase 就会跟踪已执行的变更集,并仅运行尚未执行的变更集,然后将其标记为已运行。