2013-03-25 04:36:24 +00:00
|
|
|
|
using System;
|
2014-12-02 19:21:43 +00:00
|
|
|
|
using FluentMigrator;
|
2013-09-05 00:06:24 +00:00
|
|
|
|
using NLog;
|
|
|
|
|
using NzbDrone.Common.Instrumentation;
|
2013-03-25 04:36:24 +00:00
|
|
|
|
|
2013-03-25 06:13:53 +00:00
|
|
|
|
namespace NzbDrone.Core.Datastore.Migration.Framework
|
2013-03-25 04:36:24 +00:00
|
|
|
|
{
|
2013-03-25 06:13:53 +00:00
|
|
|
|
public abstract class NzbDroneMigrationBase : FluentMigrator.Migration
|
2013-03-25 04:36:24 +00:00
|
|
|
|
{
|
2014-05-28 22:48:37 +00:00
|
|
|
|
protected readonly Logger _logger;
|
2013-09-05 00:06:24 +00:00
|
|
|
|
|
|
|
|
|
protected NzbDroneMigrationBase()
|
|
|
|
|
{
|
2014-05-28 22:48:37 +00:00
|
|
|
|
_logger = NzbDroneLogger.GetLogger(this);
|
2013-09-05 00:06:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-25 04:36:24 +00:00
|
|
|
|
protected virtual void MainDbUpgrade()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void LogDbUpgrade()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-02 19:21:43 +00:00
|
|
|
|
public int Version
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var migrationAttribute = (MigrationAttribute)Attribute.GetCustomAttribute(GetType(), typeof(MigrationAttribute));
|
|
|
|
|
return (int)migrationAttribute.Version;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-25 04:36:24 +00:00
|
|
|
|
public override void Up()
|
|
|
|
|
{
|
2019-10-14 20:21:00 +00:00
|
|
|
|
if (MigrationContext.Current.BeforeMigration != null)
|
2014-12-02 19:21:43 +00:00
|
|
|
|
{
|
2019-10-14 20:21:00 +00:00
|
|
|
|
MigrationContext.Current.BeforeMigration(this);
|
2014-12-02 19:21:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 20:21:00 +00:00
|
|
|
|
switch (MigrationContext.Current.MigrationType)
|
2013-03-25 04:36:24 +00:00
|
|
|
|
{
|
2013-06-19 01:01:08 +00:00
|
|
|
|
case MigrationType.Main:
|
2015-05-03 19:46:21 +00:00
|
|
|
|
_logger.Info("Starting migration to " + Version);
|
2013-06-19 01:01:08 +00:00
|
|
|
|
MainDbUpgrade();
|
|
|
|
|
return;
|
|
|
|
|
case MigrationType.Log:
|
2014-12-06 19:16:22 +00:00
|
|
|
|
_logger.Info("Starting migration to " + Version);
|
2013-06-19 01:01:08 +00:00
|
|
|
|
LogDbUpgrade();
|
|
|
|
|
return;
|
|
|
|
|
default:
|
|
|
|
|
LogDbUpgrade();
|
|
|
|
|
MainDbUpgrade();
|
|
|
|
|
return;
|
2013-03-25 04:36:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Down()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|