From 713c0de5f042f96a41f7dae565400fdf308ea670 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 4 Nov 2019 22:24:21 +0000 Subject: [PATCH] Fixed the issue where exisitng databases would now fail due to the DB structure changes --- src/Ombi.Store/Context/SettingsContext.cs | 2 ++ .../Context/Sqlite/ExternalSqliteContext.cs | 18 +++++++++++++++++- .../Context/Sqlite/OmbiSqliteContext.cs | 18 +++++++++++++++++- .../Context/Sqlite/SettingsSqliteContext.cs | 17 ++++++++++++++++- 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/Ombi.Store/Context/SettingsContext.cs b/src/Ombi.Store/Context/SettingsContext.cs index 1ba8c8073..9f6d52791 100644 --- a/src/Ombi.Store/Context/SettingsContext.cs +++ b/src/Ombi.Store/Context/SettingsContext.cs @@ -25,6 +25,8 @@ namespace Ombi.Store.Context public DbSet Settings { get; set; } public DbSet ApplicationConfigurations { get; set; } + + public void Seed() { using (var tran = Database.BeginTransaction()) diff --git a/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs b/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs index 4d159887f..af30920aa 100644 --- a/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs +++ b/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using System; +using Microsoft.EntityFrameworkCore; namespace Ombi.Store.Context.Sqlite { @@ -10,8 +11,23 @@ namespace Ombi.Store.Context.Sqlite if (_created) return; _created = true; + Upgrade(); Database.SetCommandTimeout(60); Database.Migrate(); } + + + private void Upgrade() + { + try + { + Database.ExecuteSqlCommand(@"INSERT INTO __EFMigrationsHistory (MigrationId,ProductVersion) + VALUES('20191103205133_Inital', '2.2.6-servicing-10079'); "); + } + catch (Exception) + { + // ignored + } + } } } \ No newline at end of file diff --git a/src/Ombi.Store/Context/Sqlite/OmbiSqliteContext.cs b/src/Ombi.Store/Context/Sqlite/OmbiSqliteContext.cs index e6e6f3186..5d6e29e31 100644 --- a/src/Ombi.Store/Context/Sqlite/OmbiSqliteContext.cs +++ b/src/Ombi.Store/Context/Sqlite/OmbiSqliteContext.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using System; +using Microsoft.EntityFrameworkCore; namespace Ombi.Store.Context.Sqlite { @@ -11,8 +12,23 @@ namespace Ombi.Store.Context.Sqlite _created = true; + Upgrade(); Database.SetCommandTimeout(60); Database.Migrate(); } + + + private void Upgrade() + { + try + { + Database.ExecuteSqlCommand(@"INSERT INTO __EFMigrationsHistory (MigrationId,ProductVersion) + VALUES('20191102235658_Inital', '2.2.6-servicing-10079'); "); + } + catch (Exception) + { + // ignored + } + } } } \ No newline at end of file diff --git a/src/Ombi.Store/Context/Sqlite/SettingsSqliteContext.cs b/src/Ombi.Store/Context/Sqlite/SettingsSqliteContext.cs index b5f429853..19e155a71 100644 --- a/src/Ombi.Store/Context/Sqlite/SettingsSqliteContext.cs +++ b/src/Ombi.Store/Context/Sqlite/SettingsSqliteContext.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using System; +using Microsoft.EntityFrameworkCore; namespace Ombi.Store.Context.Sqlite { @@ -10,8 +11,22 @@ namespace Ombi.Store.Context.Sqlite if (_created) return; _created = true; + Upgrade(); Database.SetCommandTimeout(60); Database.Migrate(); } + + private void Upgrade() + { + try + { + Database.ExecuteSqlCommand(@"INSERT INTO __EFMigrationsHistory (MigrationId,ProductVersion) + VALUES('20191103205204_Inital', '2.2.6-servicing-10079'); "); + } + catch (Exception) + { + // ignored + } + } } } \ No newline at end of file