2011-05-24 01:29:14 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Datastore
|
|
|
|
|
{
|
2011-06-15 04:31:41 +02:00
|
|
|
|
public class MigrationsHelper
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
|
|
|
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2011-06-17 08:58:50 +02:00
|
|
|
|
public static bool IsMigrated { get; private set; }
|
|
|
|
|
|
2011-06-05 08:02:31 +02:00
|
|
|
|
public static void Run(string connetionString, bool trace)
|
2011-05-24 01:29:14 +02:00
|
|
|
|
{
|
2011-06-18 04:06:20 +02:00
|
|
|
|
if (IsMigrated) return;
|
|
|
|
|
IsMigrated = true;
|
2011-06-04 20:19:22 +02:00
|
|
|
|
Logger.Info("Preparing run database migration");
|
2011-05-24 01:29:14 +02:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2011-06-05 08:02:31 +02:00
|
|
|
|
Migrator.Migrator migrator;
|
|
|
|
|
if (trace)
|
|
|
|
|
{
|
2011-06-15 04:31:41 +02:00
|
|
|
|
migrator = new Migrator.Migrator("Sqlite", connetionString, Assembly.GetAssembly(typeof(MigrationsHelper)), true, new MigrationLogger());
|
2011-06-05 08:02:31 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-06-15 04:31:41 +02:00
|
|
|
|
migrator = new Migrator.Migrator("Sqlite", connetionString, Assembly.GetAssembly(typeof(MigrationsHelper)));
|
2011-06-05 08:02:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-05-24 01:29:14 +02:00
|
|
|
|
|
2011-06-04 20:19:22 +02:00
|
|
|
|
migrator.MigrateToLastVersion();
|
2011-05-24 01:29:14 +02:00
|
|
|
|
|
2011-06-18 01:01:09 +02:00
|
|
|
|
//ForceSubSonicMigration(Connection.CreateSimpleRepository(connetionString));
|
2011-06-05 08:35:03 +02:00
|
|
|
|
|
2011-05-24 01:29:14 +02:00
|
|
|
|
Logger.Info("Database migration completed");
|
2011-06-05 08:35:03 +02:00
|
|
|
|
|
|
|
|
|
|
2011-05-24 01:29:14 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Logger.FatalException("An error has occured while migrating database", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|