【发布时间】:2014-02-12 06:01:56
【问题描述】:
我几乎同意Liquibase Best Practices 中的每一句话,除了组织你的变更日志
我有两个主要目标要实现:
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
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
我知道这有点多余,但我想再次确定,也许你可以说服我(我希望如此)这没有必要。
对于第一个目标,使用主从策略来组织变更日志就足够了,但对于第二个目标则不然,因为我没有每个版本都有一个主控。
于是我想出了一个新的策略:
每个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>
使用这种 递归 布局,每个变更日志文件都可以与同步/更新一起独立使用。
您有没有看到任何负面的方面或您有更好的策略?
我目前正在使用 JPA 2.1(eclipselink 2.5.0)、MySQL 5.7、Liquibase 3.1.0、maven 3(和 glassfish 4.0)
【问题讨论】:
标签: java mysql database-migration liquibase