title: Liquibase: best practices to organize changelogs
body: <p>I agree with almost every word in <a href="http://www.liquibase.org/bestpractices.html" rel="nofollow noreferrer">Liquibase Best Practices</a> except for <em>Organizing your changeLogs</em></p>
  
  <p>I have two main goals to achieve:</p>
  
  <p>1) on application-7.0.0 deploy:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>2) on application-7.0.0 release:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I know this is a bit redundant, but I want to be double sure, maybe you can persuade me (I hope so) this is not necessary.</p>
  
  <p>for the 1st goal using a master-slave strategy for organize changelogs is fairly sufficient, but for 2nd goal it isn't, since I don't have a master for every version.</p>
  
  <p>So I figured out a new strategy:</p>
  
  <p><img src="https://i.stack.imgur.com/7H1lQ.png" alt="new_layout"></p>
  
  <p>where each <code>changelog.xml</code> is built like:</p>
  
  <pre><code>&lt;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"&gt;
      &lt;include file="../2.0.0/changelog.xml"/&gt;
  
      &lt;changeSet author="Michele" id="3.0.0-1"&gt;
          &lt;renameColumn tableName="PERSON" oldColumnName="NAME" newColumnName="FIRSTNAME" columnDataType="VARCHAR(255)"/&gt;
      &lt;/changeSet&gt;
  
      &lt;changeSet author="Michele" id="3.0.0-2" &gt;
          &lt;addColumn tableName="PERSON"&gt;
              &lt;column name="LASTNAME" type="VARCHAR(255)"/&gt;
          &lt;/addColumn&gt;
      &lt;/changeSet&gt;
  &lt;/databaseChangeLog&gt;
  </code></pre>
  
  <p>With this <em>recursive</em> layout every changelog file can be used standalone with sync/update.</p>
  
  <p>Do you see any negative side or have you a better strategy?</p>
  
  <p><em>I'm currently using JPA 2.1 (eclipselink 2.5.0), MySQL 5.7, Liquibase 3.1.0, maven 3 (and glassfish 4.0)</em></p>