Java Liquibase:组织变更日志的最佳实践

Java Liquibase:组织变更日志的最佳实践,java,mysql,database-migration,liquibase,Java,Mysql,Database Migration,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.

除了组织变更日志外,我几乎同意中的每一个字

我有两个主要目标要实现:

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>

通过这种递归布局,每个变更日志文件都可以单独与同步/更新一起使用

你有没有看到消极的一面,或者你有更好的策略


我目前正在使用JPA2.1(eclipselink 2.5.0)、MySQL 5.7、Liquibase 3.1.0、maven 3(和glassfish 4.0)

如果每个版本的变更日志都有一个对以前版本的变更日志的include引用,那么从逻辑上讲,您所拥有的与每个版本都有include的主变更日志相同。Liquibase将嵌套的变更日志展平为一个单一的变更集平面列表,然后按顺序执行每个变更集

对于您的模型,您必须为每个新版本更改运行“更新”所针对的changelog.xml文件,但在其他情况下,它的工作原理是相同的


我不确定“使用*.ddl创建数据库”和“同步数据库”步骤的作用。通常,您只需对数据库运行liquibase update命令,liquibase跟踪哪些变更集已执行,并且只运行那些尚未将其标记为已运行的变更集。

create datebase with*.ddl只需在ddl文件中批处理执行语句即可创建表、键、ecc。同步数据库在新模式上使用liquibase syncChangeLog。不过,我会更努力地进行试验并更新我的问题,因为正如您所说,使用此模型将执行重复更新