I'm considering using Fluent NHibernate inside a desktop application which utilizes 3 different database files. (Well, 3 different kinds.)

  • DB1 may be the primary database file that contains tables A, B, C and D.
  • DB2 is really a database file that contains detailed data (X samples per second, program session will get a brand new file as they possibly can grow large) in table E.
  • DB3 is really a database file accustomed to export and import data between customers (consists of 1 row from A, 1 from B and every one of E that goes towards the given row of the and B)

Creating this isn't a real problem because the SchemaExport.Create function performs this perfectly.

The issue I face is the fact that I do not exactly understand what the easiest method to alter my tables is. More precisely, to complete multiple version updates at the same time. My application is presently version 1, shipping with database format version 1, in a few days I bump everything to version 5 - I'm able to update the database with SchemaUpdate.Execute - and then month I bump everything to version 3 and that i can perform exactly the same factor again. However I want my customers to have the ability to update from version 1 to version 3 at the same time.

Basically would do things by hand I'd produce a table known as version in every database file which consists of a version. I'd then make sure that area from the current version and perform ALTER table queries. For instance:

if (db_version < LATEST_VERSION) {
  switch (db_version + 1) {
    case 2: Execute("ALTER TABLE A..."); Execute("UPDATE A..."); break;
    case 3: Execute("ALTER TABLE B..."); break;
  }
}

By using this approach (while using the SQLite database provider directly) I'd just anticipate 1 version of my data model, 1 update service which handles everything however i will have to create my database and my data model files by hand, and that i would need to update a minimum of two .db files and a pair of update services (one for every db type). Which may be viewed as duplicate work. (I discovered the database migration of Banshee a good example of what i'm saying with this.)

By utilizing NHibernate I eliminate the entire process of maintaining a database file along with a data model, but the only method I can tell on doing updates from one to three would be to have a legacy version of every data model and make a move like:

namespace Version1 {
  public class A {}
  DoUpdate();
}

namespace Version2 {
  public class A {}
  DoUpdate();
}

Shall We Be Held totally searching only at that the wrong manner or perhaps is my situation only to complex and would I be best while using manual approach? What will be the best answer to update and migrate from version one to three using Fluent NHibernate? Or would anybody recommend while using manual approach, and when why?

I can not answer how to get this done with Fluent NHibernate, because I have never determined a great way. For me, it is not established to handle real database migrations. So, for those my Fluent NHibernate projects, I am using http://code.google.com/p/migratordotnet/ It is not perfect, but it works.