Radarr/src/NzbDrone.Core/Datastore/Migration/Framework/NzbDroneMigrationBase.cs

76 lines
1.8 KiB
C#
Raw Normal View History

using System;
using FluentMigrator;
2013-09-05 00:06:24 +00:00
using NLog;
using NzbDrone.Common.Instrumentation;
2013-03-25 06:13:53 +00:00
namespace NzbDrone.Core.Datastore.Migration.Framework
{
2013-03-25 06:13:53 +00:00
public abstract class NzbDroneMigrationBase : FluentMigrator.Migration
{
protected readonly Logger _logger;
2014-12-02 20:08:37 +00:00
private MigrationContext _migrationContext;
2013-09-05 00:06:24 +00:00
protected NzbDroneMigrationBase()
{
_logger = NzbDroneLogger.GetLogger(this);
2013-09-05 00:06:24 +00:00
}
protected virtual void MainDbUpgrade()
{
}
protected virtual void LogDbUpgrade()
{
}
public int Version
{
get
{
var migrationAttribute = (MigrationAttribute)Attribute.GetCustomAttribute(GetType(), typeof(MigrationAttribute));
return (int)migrationAttribute.Version;
}
}
public MigrationContext Context
{
get
{
2014-12-02 20:08:37 +00:00
if (_migrationContext == null)
{
_migrationContext = (MigrationContext)ApplicationContext;
}
return _migrationContext;
}
}
public override void Up()
{
2013-07-05 03:56:27 +00:00
if (Context.BeforeMigration != null)
{
Context.BeforeMigration(this);
}
switch (Context.MigrationType)
{
2013-06-19 01:01:08 +00:00
case MigrationType.Main:
MainDbUpgrade();
return;
case MigrationType.Log:
LogDbUpgrade();
return;
default:
LogDbUpgrade();
MainDbUpgrade();
return;
}
}
public override void Down()
{
throw new NotImplementedException();
}
}
}