jellyfin/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs

63 lines
2.1 KiB
C#
Raw Normal View History

2015-10-29 13:28:05 +00:00
using System.Threading.Tasks;
using MediaBrowser.Common.ScheduledTasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Server.Implementations.Persistence;
namespace MediaBrowser.Server.Startup.Common.Migrations
{
public class DbMigration : IVersionMigration
{
private readonly IServerConfigurationManager _config;
private readonly ITaskManager _taskManager;
public DbMigration(IServerConfigurationManager config, ITaskManager taskManager)
{
_config = config;
_taskManager = taskManager;
}
public void Run()
{
2016-06-15 18:56:37 +00:00
// If a forced migration is required, do that now
2016-02-15 04:46:51 +00:00
if (_config.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion)
2015-10-29 13:28:05 +00:00
{
2016-02-15 04:46:51 +00:00
if (!_config.Configuration.IsStartupWizardCompleted)
{
_config.Configuration.MigrationVersion = CleanDatabaseScheduledTask.MigrationVersion;
_config.SaveConfiguration();
return;
}
2016-02-03 20:52:45 +00:00
_taskManager.SuspendTriggers = true;
2016-02-01 19:54:49 +00:00
CleanDatabaseScheduledTask.EnableUnavailableMessage = true;
2015-11-02 17:25:01 +00:00
Task.Run(async () =>
{
2016-02-15 04:46:51 +00:00
await Task.Delay(1000).ConfigureAwait(false);
2015-10-29 13:28:05 +00:00
2016-02-03 20:52:45 +00:00
_taskManager.Execute<CleanDatabaseScheduledTask>();
2015-11-02 17:25:01 +00:00
});
2016-06-15 18:56:37 +00:00
return;
}
if (_config.Configuration.SchemaVersion < SqliteItemRepository.LatestSchemaVersion)
{
if (!_config.Configuration.IsStartupWizardCompleted)
{
_config.Configuration.SchemaVersion = SqliteItemRepository.LatestSchemaVersion;
_config.SaveConfiguration();
return;
}
Task.Run(async () =>
{
await Task.Delay(1000).ConfigureAwait(false);
_taskManager.Execute<CleanDatabaseScheduledTask>();
});
2015-11-02 17:25:01 +00:00
}
2015-10-29 13:28:05 +00:00
}
}
}