1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-14 11:23:42 +02:00
Sonarr/NzbDrone.Core/Datastore/MigrationsHelper.cs

54 lines
1.4 KiB
C#
Raw Normal View History

2013-02-17 00:10:20 +03:00
using System.Linq;
using System;
2011-05-24 02:29:14 +03:00
using System.Reflection;
using NLog;
namespace NzbDrone.Core.Datastore
{
2011-06-15 05:31:41 +03:00
public class MigrationsHelper
2011-05-24 02:29:14 +03:00
{
2013-02-04 07:18:59 +03:00
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
2011-05-24 02:29:14 +03:00
2013-02-04 07:18:59 +03:00
public static void Run(string connectionString, bool trace)
2011-05-24 02:29:14 +03:00
{
2013-02-17 02:29:21 +03:00
SqlCeProxy.EnsureDatabase(connectionString);
2011-06-23 09:56:17 +03:00
2013-02-04 07:18:59 +03:00
logger.Trace("Preparing to run database migration");
2011-05-24 02:29:14 +03:00
try
{
2011-06-05 09:02:31 +03:00
Migrator.Migrator migrator;
if (trace)
{
2013-02-04 07:18:59 +03:00
migrator = new Migrator.Migrator("sqlserverce", connectionString, Assembly.GetAssembly(typeof(MigrationsHelper)), true, new MigrationLogger());
2011-06-05 09:02:31 +03:00
}
else
{
2013-02-04 07:18:59 +03:00
migrator = new Migrator.Migrator("sqlserverce", connectionString, Assembly.GetAssembly(typeof(MigrationsHelper)));
2011-06-05 09:02:31 +03:00
}
2013-02-17 01:36:29 +03:00
2011-06-04 21:19:22 +03:00
migrator.MigrateToLastVersion();
2013-02-04 07:18:59 +03:00
logger.Info("Database migration completed");
2011-06-05 09:35:03 +03:00
2011-05-24 02:29:14 +03:00
}
catch (Exception e)
{
2013-02-04 07:18:59 +03:00
logger.FatalException("An error has occurred while migrating database", e);
2013-01-19 22:42:06 +03:00
throw;
2011-05-24 02:29:14 +03:00
}
}
2013-02-17 02:29:21 +03:00
2011-06-24 05:04:07 +03:00
public static string GetIndexName(string tableName, params string[] columns)
{
return String.Format("IX_{0}_{1}", tableName, String.Join("_", columns));
}
2011-05-24 02:29:14 +03:00
}
2011-06-23 09:56:17 +03:00
2011-05-24 02:29:14 +03:00
}