Ya.
Ya.

Reputation: 2627

dropwizard and liquibase: how to maintain ongoing database changes

I understand dropwizard expects all DB migrations to be in migrations.xml. Let's say I'm starting a new project and create my tables:

<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>

At the next iteration I have to add a new column so I ad another changeSet to migrations.xml:

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

Then let's say I have to make a column longer so I add:

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

And so it goes. I keep appending all changes to my migrations.xml which grows indefinitely. On a large project it's just a matter of time when it becomes unmanagable. Does anyone has any recommendations for strategy to maintain ongoing database changes?

Upvotes: 2

Views: 1701

Answers (1)

Natan
Natan

Reputation: 2858

You can divide your migrations.xml file to multiple files as documented here apparently.

<?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>

Upvotes: 1

Related Questions