SubSonic does what you need. It has a migration class for use with sonic commander. I changed the code and put it at the beginning of my applications, and it checks the difference in version and updates automatically. Here's how you need to configure it:
- You need to add a migration class with version. You could take a look at this tutorial if you have not used SubSonic before. The next class is saved as \ Migrations \ 001_initial.cs, if you called migrate.exe (inside VS) from subsonic, it will update the current db to the latest available version. You need to save the three-digit version prefix as the file name for migrate.exe for proper operation, as indicated in the tutorial. As for the class name, the migration class I wrote requires an underscore and a three-digit version prefix for proper version detection.
// * I donβt know why I need this line to make the code block below
namespace MyApps.Migrations { public class _001_Initial : Migration { public override void Up() {
- Called by CheckForMigration () at launch of your application. IsUpdateAvailable will indicate that you need to update db. You just need to call Migrate (). IsAppVersionOlder indicates that your application was created with an older version of the db schema (perhaps another copy of the new applications updated db). With the help of, you can prevent the launch of old applications and damage the updated db.
//
using System; using System.Collections.Generic; using SubSonic; using SubSonic.Migrations; namespace MyApps.Migrations { internal static class MigrationHelper { const string NameSpace = "MyApps.Migrations"; private const string SCHEMA_INFO = "SubSonicSchemaInfo"; public static int CurrentVersion { get { return currentVersion; } } public static int AppVersion { get { return latestVersion; } } public static bool IsUpdateAvailable { get { return (updateVersion.Count > 0); } } public static bool IsAppVersionOlder { get; private set; } public static bool Checked { get; internal set; } private static int currentVersion; private static int latestVersion; private static List<string> updateVersion; private static List<string> availableVersion; static MigrationHelper() { Checked = false; }
A table called SubSonicSchemaInfo will be automatically added by SubSonic to your db to track the version of db.
This is a long post, I hope I havenβt missed anything.
source share