【问题标题】:dropwizard and liquibase: how to maintain ongoing database changesdropwizard 和 liquibase:如何维护持续的数据库更改
【发布时间】:2015-05-28 22:50:41
【问题描述】:

我了解 dropwizard 期望所有数据库迁移都在 migrations.xml 中。 假设我要开始一个新项目并创建我的表:

<changeSet id="1" author="codahale">
    <createTable tableName="people">
        <column name="id" type="bigint" autoIncrement="true">
            <constraints primaryKey="true" nullable="false"/>
        </column>
        <column name="fullname" type="varchar(255)">
            <constraints nullable="false"/>
        </column>
        <column name="jobtitle" type="varchar(255)"/>
    </createTable>
</changeSet>

在下一次迭代中,我必须添加一个新列,因此我将另一个 changeSet 添加到 migrations.xml:

<changeSet id="2" author="dbdemopostgres">
    <addColumn tableName="people">
        <column name="description" type="varchar(255)">
            <constraints nullable="false"/>
        </column>
    </addColumn>
</changeSet>

然后假设我必须使一列更长,所以我添加:

<changeSet id="3" author="dbdemopostgres">
    <modifyDataType tableName="people" columnName="description" newDataType="varchar(300)"/>        
</changeSet>

就这样。我不断将所有更改附加到无限增长的 migrations.xml 中。在一个大型项目中,它变得难以管理只是时间问题。有人对维护持续数据库更改的策略有任何建议吗?

【问题讨论】:

  • 有一些方法可以通过将变更日志拆分为多个文件来管理此问题,或者在某个任意时间点决定您将只是“重新设置”数据库的基线,但我不认为这是您需要担心很长时间的事情。我知道一些组织的变更日志非常大(> 13,000 个变更集)并且仍然非常易于管理。过程还是一样的。

标签: liquibase dropwizard


【解决方案1】:

显然,您可以将 migrations.xml 文件划分为多个文件,如 documented here

<?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.1.xsd">

  <include file="com/example/db/changelog/db.changelog-1.0.xml"/> 
  <include file="com/example/db/changelog/db.changelog-1.1.xml"/> 
  <include file="com/example/db/changelog/db.changelog-2.0.xml"/> 
</databaseChangeLog>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多