title: How to perform multiple database alterations at once using NHibernate?
body: <p>I am looking into using Fluent NHibernate in a desktop application which uses 3 different database files. (Well, 3 different types.)</p>
  
  <ul>
  <li>DB1 is the main database file containing tables A, B, C and D. </li>
  <li>DB2 is a database file containing detailed data (X samples per second, program session will receive a new file as they can grow very large) in table E.</li>
  <li>DB3 is a database file used to export and import data between users (contains 1 row from  A, 1 from B and all of E that belongs to the given row of A and B)</li>
  </ul>
  
  <p>Creating this is not really a problem as the SchemaExport.Create function does this perfectly.</p>
  
  <p>The problem I face is that I don't exactly know what the best way to alter my tables is. More precisely, to do multiple version updates at once. My application is currently version 1, shipping with database format version 1, next week I bump everything to version 2 - I can update the database with SchemaUpdate.Execute - and next month I bump everything to version 3 and I can do the same thing again. But I want my users to be able to update from version 1 to version 3 at once.</p>
  
  <p>If I would do things manually I would create a table called version in each database file which contains a version. I would then check that field against the current version and perform ALTER table queries. For example:</p>
  
  <pre><code>if (db_version &lt; LATEST_VERSION) {
    switch (db_version + 1) {
      case 2: Execute("ALTER TABLE A..."); Execute("UPDATE A..."); break;
      case 3: Execute("ALTER TABLE B..."); break;
    }
  }
  </code></pre>
  
  <p>Using this approach (when using the SQLite database provider directly) I would only have to foresee 1 version of my data model, 1 update service which handles everything but I would need to create my database and my data model files manually, and I would have to update at least two .db files and 2 update services (one for each db type). Which can be seen as duplicate work. (I found the <a href="http://git.gnome.org/browse/banshee/tree/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs" rel="nofollow">database migration of Banshee</a> an example of what I mean by this.)</p>
  
  <p>By using NHibernate I eliminate the process of maintaining a database file and a data model, but the only way I can see on doing updates from 1 to 3 is to keep a legacy version of each data model and do something like:</p>
  
  <pre><code>namespace Version1 {
    public class A {}
    DoUpdate();
  }
  
  namespace Version2 {
    public class A {}
    DoUpdate();
  }
  </code></pre>
  
  <p>Am I totally looking at this the wrong way or is my case simply to complex and would I be better off using the manual approach? 
  What would be the best solution to update and migrate from version 1 to 3 using Fluent NHibernate? Or would anyone recommend using the manual approach, and if so why?</p>