From 560c3c3eadfc18d8b6f1219d22a30ba56f7d4457 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sun, 3 Nov 2019 21:53:22 +0000 Subject: [PATCH] Finished it! --- .../Rules/Request/SonarrCacheRequestRule.cs | 4 +- .../Rules/Search/SonarrCacheSearchRule.cs | 4 +- src/Ombi.Core/Rule/Rules/SonarrCacheRule.cs | 4 +- src/Ombi.DependencyInjection/IocExtensions.cs | 8 +- .../Jobs/Couchpotato/CouchPotatoSync.cs | 4 +- .../Jobs/Lidarr/LidarrAlbumSync.cs | 4 +- .../Jobs/Lidarr/LidarrArtistSync.cs | 4 +- src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs | 4 +- .../Jobs/SickRage/SickRageSync.cs | 4 +- src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs | 4 +- src/Ombi.Store/Context/ExternalContext.cs | 43 +-- src/Ombi.Store/Context/IExternalContext.cs | 21 -- src/Ombi.Store/Context/ISettingsContext.cs | 11 - .../Context/MySql/ExternalMySqlContext.cs | 16 + .../Context/{ => MySql}/OmbiMySqlContext.cs | 3 +- .../Context/MySql/SettingsMySqlContext.cs | 16 + src/Ombi.Store/Context/OmbiContext.cs | 15 - src/Ombi.Store/Context/SettingsContext.cs | 37 +- .../Context/Sqlite/ExternalSqliteContext.cs | 17 + .../Context/{ => Sqlite}/OmbiSqliteContext.cs | 2 +- .../Context/Sqlite/SettingsSqliteContext.cs | 17 + src/Ombi.Store/Migration.txt | 4 +- .../20191103213915_Inital.Designer.cs | 315 ++++++++++++++++++ .../ExternalMySql/20191103213915_Inital.cs | 310 +++++++++++++++++ .../ExternalMySqlContextModelSnapshot.cs | 313 +++++++++++++++++ .../20191103205133_Inital.Designer.cs | 314 +++++++++++++++++ .../ExternalSqlite/20191103205133_Inital.cs | 309 +++++++++++++++++ .../ExternalSqliteContextModelSnapshot.cs | 312 +++++++++++++++++ .../20191102235852_Inital.Designer.cs | 1 + .../OmbiMySqlContextModelSnapshot.cs | 1 + .../20191102235658_Inital.Designer.cs | 1 + .../OmbiSqliteContextModelSnapshot.cs | 1 + .../20191103205915_Inital.Designer.cs | 51 +++ .../SettingsMySql/20191103205915_Inital.cs | 48 +++ .../SettingsMySqlContextModelSnapshot.cs | 49 +++ .../20191103205204_Inital.Designer.cs | 50 +++ .../SettingsSqlite/20191103205204_Inital.cs | 47 +++ .../SettingsSqliteContextModelSnapshot.cs | 48 +++ .../Repository/ApplicationConfigRepository.cs | 4 +- .../Repository/SettingsJsonRepository.cs | 4 +- src/Ombi/Extensions/DatabaseExtensions.cs | 40 ++- src/Ombi/Program.cs | 274 ++++----------- src/Ombi/Startup.cs | 4 +- 43 files changed, 2395 insertions(+), 347 deletions(-) delete mode 100644 src/Ombi.Store/Context/IExternalContext.cs delete mode 100644 src/Ombi.Store/Context/ISettingsContext.cs create mode 100644 src/Ombi.Store/Context/MySql/ExternalMySqlContext.cs rename src/Ombi.Store/Context/{ => MySql}/OmbiMySqlContext.cs (86%) create mode 100644 src/Ombi.Store/Context/MySql/SettingsMySqlContext.cs create mode 100644 src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs rename src/Ombi.Store/Context/{ => Sqlite}/OmbiSqliteContext.cs (91%) create mode 100644 src/Ombi.Store/Context/Sqlite/SettingsSqliteContext.cs create mode 100644 src/Ombi.Store/Migrations/ExternalMySql/20191103213915_Inital.Designer.cs create mode 100644 src/Ombi.Store/Migrations/ExternalMySql/20191103213915_Inital.cs create mode 100644 src/Ombi.Store/Migrations/ExternalMySql/ExternalMySqlContextModelSnapshot.cs create mode 100644 src/Ombi.Store/Migrations/ExternalSqlite/20191103205133_Inital.Designer.cs create mode 100644 src/Ombi.Store/Migrations/ExternalSqlite/20191103205133_Inital.cs create mode 100644 src/Ombi.Store/Migrations/ExternalSqlite/ExternalSqliteContextModelSnapshot.cs create mode 100644 src/Ombi.Store/Migrations/SettingsMySql/20191103205915_Inital.Designer.cs create mode 100644 src/Ombi.Store/Migrations/SettingsMySql/20191103205915_Inital.cs create mode 100644 src/Ombi.Store/Migrations/SettingsMySql/SettingsMySqlContextModelSnapshot.cs create mode 100644 src/Ombi.Store/Migrations/SettingsSqlite/20191103205204_Inital.Designer.cs create mode 100644 src/Ombi.Store/Migrations/SettingsSqlite/20191103205204_Inital.cs create mode 100644 src/Ombi.Store/Migrations/SettingsSqlite/SettingsSqliteContextModelSnapshot.cs diff --git a/src/Ombi.Core/Rule/Rules/Request/SonarrCacheRequestRule.cs b/src/Ombi.Core/Rule/Rules/Request/SonarrCacheRequestRule.cs index 625407f3c..e734fe4a6 100644 --- a/src/Ombi.Core/Rule/Rules/Request/SonarrCacheRequestRule.cs +++ b/src/Ombi.Core/Rule/Rules/Request/SonarrCacheRequestRule.cs @@ -7,12 +7,12 @@ namespace Ombi.Core.Rule.Rules.Request { public class SonarrCacheRequestRule : BaseRequestRule, IRules { - public SonarrCacheRequestRule(IExternalContext ctx) + public SonarrCacheRequestRule(ExternalContext ctx) { _ctx = ctx; } - private readonly IExternalContext _ctx; + private readonly ExternalContext _ctx; public Task Execute(BaseRequest obj) { diff --git a/src/Ombi.Core/Rule/Rules/Search/SonarrCacheSearchRule.cs b/src/Ombi.Core/Rule/Rules/Search/SonarrCacheSearchRule.cs index 03bdbe091..24f2712d7 100644 --- a/src/Ombi.Core/Rule/Rules/Search/SonarrCacheSearchRule.cs +++ b/src/Ombi.Core/Rule/Rules/Search/SonarrCacheSearchRule.cs @@ -34,12 +34,12 @@ namespace Ombi.Core.Rule.Rules.Search { public class SonarrCacheSearchRule : BaseSearchRule, IRules { - public SonarrCacheSearchRule(IExternalContext ctx) + public SonarrCacheSearchRule(ExternalContext ctx) { _ctx = ctx; } - private readonly IExternalContext _ctx; + private readonly ExternalContext _ctx; public Task Execute(SearchViewModel obj) { diff --git a/src/Ombi.Core/Rule/Rules/SonarrCacheRule.cs b/src/Ombi.Core/Rule/Rules/SonarrCacheRule.cs index 7eac05d56..ca7ccb6ce 100644 --- a/src/Ombi.Core/Rule/Rules/SonarrCacheRule.cs +++ b/src/Ombi.Core/Rule/Rules/SonarrCacheRule.cs @@ -10,12 +10,12 @@ namespace Ombi.Core.Rule.Rules { public class SonarrCacheRule { - public SonarrCacheRule(IExternalContext ctx) + public SonarrCacheRule(ExternalContext ctx) { _ctx = ctx; } - private readonly IExternalContext _ctx; + private readonly ExternalContext _ctx; public async Task Execute(BaseRequest obj) { diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index 38cb51acd..df0162c1a 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -136,12 +136,12 @@ namespace Ombi.DependencyInjection public static void RegisterStore(this IServiceCollection services) { //services.AddDbContext(); - services.AddDbContext(); - services.AddDbContext(); + //services.AddDbContext(); + //services.AddDbContext(); //services.AddScoped(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6 - services.AddScoped(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6 - services.AddScoped(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6 + //services.AddScoped(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6 + //services.AddScoped(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6 services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs b/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs index 5c3cf342a..f85563670 100644 --- a/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs +++ b/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs @@ -43,7 +43,7 @@ namespace Ombi.Schedule.Jobs.Couchpotato public class CouchPotatoSync : ICouchPotatoSync { public CouchPotatoSync(ISettingsService cpSettings, - ICouchPotatoApi api, ILogger log, IExternalContext ctx) + ICouchPotatoApi api, ILogger log, ExternalContext ctx) { _settings = cpSettings; _api = api; @@ -55,7 +55,7 @@ namespace Ombi.Schedule.Jobs.Couchpotato private readonly ISettingsService _settings; private readonly ICouchPotatoApi _api; private readonly ILogger _log; - private readonly IExternalContext _ctx; + private readonly ExternalContext _ctx; public async Task Execute(IJobExecutionContext job) { diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs index 0d48efbc0..09bd787e7 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs @@ -17,7 +17,7 @@ namespace Ombi.Schedule.Jobs.Lidarr { public class LidarrAlbumSync : ILidarrAlbumSync { - public LidarrAlbumSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, IExternalContext ctx, + public LidarrAlbumSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, ExternalContext ctx, IBackgroundJobClient job, ILidarrAvailabilityChecker availability) { _lidarrSettings = lidarr; @@ -31,7 +31,7 @@ namespace Ombi.Schedule.Jobs.Lidarr private readonly ISettingsService _lidarrSettings; private readonly ILidarrApi _lidarrApi; private readonly ILogger _logger; - private readonly IExternalContext _ctx; + private readonly ExternalContext _ctx; private readonly IBackgroundJobClient _job; private readonly ILidarrAvailabilityChecker _availability; diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs index 1602f28b5..317b5821e 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs @@ -18,7 +18,7 @@ namespace Ombi.Schedule.Jobs.Lidarr { public class LidarrArtistSync : ILidarrArtistSync { - public LidarrArtistSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, IExternalContext ctx, + public LidarrArtistSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, ExternalContext ctx, IBackgroundJobClient background, ILidarrAlbumSync album) { _lidarrSettings = lidarr; @@ -32,7 +32,7 @@ namespace Ombi.Schedule.Jobs.Lidarr private readonly ISettingsService _lidarrSettings; private readonly ILidarrApi _lidarrApi; private readonly ILogger _logger; - private readonly IExternalContext _ctx; + private readonly ExternalContext _ctx; private readonly IBackgroundJobClient _job; private readonly ILidarrAlbumSync _albumSync; diff --git a/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs b/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs index 56499aea6..56a97b0ab 100644 --- a/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs +++ b/src/Ombi.Schedule/Jobs/Radarr/RadarrSync.cs @@ -17,7 +17,7 @@ namespace Ombi.Schedule.Jobs.Radarr { public class RadarrSync : IRadarrSync { - public RadarrSync(ISettingsService radarr, IRadarrApi radarrApi, ILogger log, IExternalContext ctx) + public RadarrSync(ISettingsService radarr, IRadarrApi radarrApi, ILogger log, ExternalContext ctx) { RadarrSettings = radarr; RadarrApi = radarrApi; @@ -29,7 +29,7 @@ namespace Ombi.Schedule.Jobs.Radarr private ISettingsService RadarrSettings { get; } private IRadarrApi RadarrApi { get; } private ILogger Logger { get; } - private readonly IExternalContext _ctx; + private readonly ExternalContext _ctx; private static readonly SemaphoreSlim SemaphoreSlim = new SemaphoreSlim(1, 1); diff --git a/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs b/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs index b6cca4c78..fbf594281 100644 --- a/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs +++ b/src/Ombi.Schedule/Jobs/SickRage/SickRageSync.cs @@ -17,7 +17,7 @@ namespace Ombi.Schedule.Jobs.SickRage { public class SickRageSync : ISickRageSync { - public SickRageSync(ISettingsService s, ISickRageApi api, ILogger l, IExternalContext ctx) + public SickRageSync(ISettingsService s, ISickRageApi api, ILogger l, ExternalContext ctx) { _settings = s; _api = api; @@ -29,7 +29,7 @@ namespace Ombi.Schedule.Jobs.SickRage private readonly ISettingsService _settings; private readonly ISickRageApi _api; private readonly ILogger _log; - private readonly IExternalContext _ctx; + private readonly ExternalContext _ctx; public async Task Execute(IJobExecutionContext job) { diff --git a/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs b/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs index f375ef064..e8707cc3a 100644 --- a/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs +++ b/src/Ombi.Schedule/Jobs/Sonarr/SonarrSync.cs @@ -20,7 +20,7 @@ namespace Ombi.Schedule.Jobs.Sonarr { public class SonarrSync : ISonarrSync { - public SonarrSync(ISettingsService s, ISonarrApi api, ILogger l, IExternalContext ctx) + public SonarrSync(ISettingsService s, ISonarrApi api, ILogger l, ExternalContext ctx) { _settings = s; _api = api; @@ -32,7 +32,7 @@ namespace Ombi.Schedule.Jobs.Sonarr private readonly ISettingsService _settings; private readonly ISonarrApi _api; private readonly ILogger _log; - private readonly IExternalContext _ctx; + private readonly ExternalContext _ctx; public async Task Execute(IJobExecutionContext job) { diff --git a/src/Ombi.Store/Context/ExternalContext.cs b/src/Ombi.Store/Context/ExternalContext.cs index 19cb77fc4..99ec4cb5f 100644 --- a/src/Ombi.Store/Context/ExternalContext.cs +++ b/src/Ombi.Store/Context/ExternalContext.cs @@ -5,16 +5,22 @@ using Ombi.Store.Entities; namespace Ombi.Store.Context { - public sealed class ExternalContext : DbContext, IExternalContext + public abstract class ExternalContext : DbContext { - private static bool _created; - public ExternalContext() + protected ExternalContext(DbContextOptions options) : base(options) { - if (_created) return; - _created = true; - Database.SetCommandTimeout(60); - Database.Migrate(); + } + + /// + /// This allows a sub class to call the base class 'DbContext' non typed constructor + /// This is need because instances of the subclasses will use a specific typed DbContextOptions + /// which can not be converted into the parameter in the above constructor + /// + /// + protected ExternalContext(DbContextOptions options) + : base(options) + { } public DbSet PlexServerContent { get; set; } @@ -32,16 +38,6 @@ namespace Ombi.Store.Context public DbSet SickRageCache { get; set; } public DbSet SickRageEpisodeCache { get; set; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - var i = StoragePathSingleton.Instance; - if (string.IsNullOrEmpty(i.StoragePath)) - { - i.StoragePath = string.Empty; - } - optionsBuilder.UseSqlite($"Data Source={Path.Combine(i.StoragePath, "OmbiExternal.db")}"); - } - protected override void OnModelCreating(ModelBuilder builder) { builder.Entity().HasMany(x => x.Episodes) @@ -57,18 +53,5 @@ namespace Ombi.Store.Context base.OnModelCreating(builder); } - - - public void Seed() - { - // VACUUM; - Database.ExecuteSqlCommand("VACUUM;"); - - using (var tran = Database.BeginTransaction()) - { - SaveChanges(); - tran.Commit(); - } - } } } \ No newline at end of file diff --git a/src/Ombi.Store/Context/IExternalContext.cs b/src/Ombi.Store/Context/IExternalContext.cs deleted file mode 100644 index 3f5d79a79..000000000 --- a/src/Ombi.Store/Context/IExternalContext.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Ombi.Store.Entities; - -namespace Ombi.Store.Context -{ - public interface IExternalContext : IDbContext - { - DbSet CouchPotatoCache { get; set; } - DbSet EmbyContent { get; set; } - DbSet EmbyEpisode { get; set; } - DbSet LidarrAlbumCache { get; set; } - DbSet LidarrArtistCache { get; set; } - DbSet PlexEpisode { get; set; } - DbSet PlexServerContent { get; set; } - DbSet RadarrCache { get; set; } - DbSet SickRageCache { get; set; } - DbSet SickRageEpisodeCache { get; set; } - DbSet SonarrCache { get; set; } - DbSet SonarrEpisodeCache { get; set; } - } -} \ No newline at end of file diff --git a/src/Ombi.Store/Context/ISettingsContext.cs b/src/Ombi.Store/Context/ISettingsContext.cs deleted file mode 100644 index 3c209c68a..000000000 --- a/src/Ombi.Store/Context/ISettingsContext.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Ombi.Store.Entities; - -namespace Ombi.Store.Context -{ - public interface ISettingsContext : IDbContext - { - DbSet ApplicationConfigurations { get; set; } - DbSet Settings { get; set; } - } -} \ No newline at end of file diff --git a/src/Ombi.Store/Context/MySql/ExternalMySqlContext.cs b/src/Ombi.Store/Context/MySql/ExternalMySqlContext.cs new file mode 100644 index 000000000..6b569d591 --- /dev/null +++ b/src/Ombi.Store/Context/MySql/ExternalMySqlContext.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; + +namespace Ombi.Store.Context.MySql +{ + public sealed class ExternalMySqlContext : ExternalContext + { + private static bool _created; + public ExternalMySqlContext(DbContextOptions options) : base(options) + { + if (_created) return; + + _created = true; + Database.Migrate(); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Store/Context/OmbiMySqlContext.cs b/src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs similarity index 86% rename from src/Ombi.Store/Context/OmbiMySqlContext.cs rename to src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs index 1437846e3..a0d11f76a 100644 --- a/src/Ombi.Store/Context/OmbiMySqlContext.cs +++ b/src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs @@ -1,7 +1,6 @@ using Microsoft.EntityFrameworkCore; -using Ombi.Store.Entities; -namespace Ombi.Store.Context +namespace Ombi.Store.Context.MySql { public sealed class OmbiMySqlContext : OmbiContext { diff --git a/src/Ombi.Store/Context/MySql/SettingsMySqlContext.cs b/src/Ombi.Store/Context/MySql/SettingsMySqlContext.cs new file mode 100644 index 000000000..cc450e715 --- /dev/null +++ b/src/Ombi.Store/Context/MySql/SettingsMySqlContext.cs @@ -0,0 +1,16 @@ +using Microsoft.EntityFrameworkCore; + +namespace Ombi.Store.Context.MySql +{ + public sealed class SettingsMySqlContext : SettingsContext + { + private static bool _created; + public SettingsMySqlContext(DbContextOptions options) : base(options) + { + if (_created) return; + + _created = true; + Database.Migrate(); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Store/Context/OmbiContext.cs b/src/Ombi.Store/Context/OmbiContext.cs index b6e23a377..4694f1151 100644 --- a/src/Ombi.Store/Context/OmbiContext.cs +++ b/src/Ombi.Store/Context/OmbiContext.cs @@ -50,21 +50,6 @@ namespace Ombi.Store.Context public DbSet UserNotificationPreferences { get; set; } public DbSet UserQualityProfileses { get; set; } public DbSet RequestQueue { get; set; } - protected override void OnModelCreating(ModelBuilder builder) - { - builder.Entity().HasMany(x => x.Episodes) - .WithOne(x => x.Series) - .HasPrincipalKey(x => x.Key) - .HasForeignKey(x => x.GrandparentKey); - - builder.Entity() - .HasOne(p => p.Series) - .WithMany(b => b.Episodes) - .HasPrincipalKey(x => x.EmbyId) - .HasForeignKey(p => p.ParentId); - - base.OnModelCreating(builder); - } public void Seed() { diff --git a/src/Ombi.Store/Context/SettingsContext.cs b/src/Ombi.Store/Context/SettingsContext.cs index 48ef0e6c7..1ba8c8073 100644 --- a/src/Ombi.Store/Context/SettingsContext.cs +++ b/src/Ombi.Store/Context/SettingsContext.cs @@ -1,39 +1,32 @@ -using System.IO; -using System.Linq; +using System.Linq; using Microsoft.EntityFrameworkCore; -using Ombi.Helpers; using Ombi.Store.Entities; namespace Ombi.Store.Context { - public sealed class SettingsContext : DbContext, ISettingsContext + public abstract class SettingsContext : DbContext { - private static bool _created; - public SettingsContext() + protected SettingsContext(DbContextOptions options) : base(options) { - if (_created) return; - _created = true; - Database.SetCommandTimeout(60); - Database.Migrate(); } - + + /// + /// This allows a sub class to call the base class 'DbContext' non typed constructor + /// This is need because instances of the subclasses will use a specific typed DbContextOptions + /// which can not be converted into the parameter in the above constructor + /// + /// + protected SettingsContext(DbContextOptions options) + : base(options) + { + } + public DbSet Settings { get; set; } public DbSet ApplicationConfigurations { get; set; } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - var i = StoragePathSingleton.Instance; - if (string.IsNullOrEmpty(i.StoragePath)) - { - i.StoragePath = string.Empty; - } - optionsBuilder.UseSqlite($"Data Source={Path.Combine(i.StoragePath, "OmbiSettings.db")}"); - } - public void Seed() { - using (var tran = Database.BeginTransaction()) { // Add the tokens diff --git a/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs b/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs new file mode 100644 index 000000000..4d159887f --- /dev/null +++ b/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; + +namespace Ombi.Store.Context.Sqlite +{ + public sealed class ExternalSqliteContext : ExternalContext + { + private static bool _created; + public ExternalSqliteContext(DbContextOptions options) : base(options) + { + if (_created) return; + + _created = true; + Database.SetCommandTimeout(60); + Database.Migrate(); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Store/Context/OmbiSqliteContext.cs b/src/Ombi.Store/Context/Sqlite/OmbiSqliteContext.cs similarity index 91% rename from src/Ombi.Store/Context/OmbiSqliteContext.cs rename to src/Ombi.Store/Context/Sqlite/OmbiSqliteContext.cs index 2ccfc1dac..e6e6f3186 100644 --- a/src/Ombi.Store/Context/OmbiSqliteContext.cs +++ b/src/Ombi.Store/Context/Sqlite/OmbiSqliteContext.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore; -namespace Ombi.Store.Context +namespace Ombi.Store.Context.Sqlite { public sealed class OmbiSqliteContext : OmbiContext { diff --git a/src/Ombi.Store/Context/Sqlite/SettingsSqliteContext.cs b/src/Ombi.Store/Context/Sqlite/SettingsSqliteContext.cs new file mode 100644 index 000000000..b5f429853 --- /dev/null +++ b/src/Ombi.Store/Context/Sqlite/SettingsSqliteContext.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; + +namespace Ombi.Store.Context.Sqlite +{ + public sealed class SettingsSqliteContext : SettingsContext + { + private static bool _created; + public SettingsSqliteContext(DbContextOptions options) : base(options) + { + if (_created) return; + + _created = true; + Database.SetCommandTimeout(60); + Database.Migrate(); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Store/Migration.txt b/src/Ombi.Store/Migration.txt index 3b54d72f5..5d1131a75 100644 --- a/src/Ombi.Store/Migration.txt +++ b/src/Ombi.Store/Migration.txt @@ -1 +1,3 @@ -dotnet ef migrations add Inital --context OmbiContext --startup-project ../Ombi/Ombi.csproj \ No newline at end of file +dotnet ef migrations add Inital --context OmbiContext --startup-project ../Ombi/Ombi.csproj + +If running migrations for any db provider other than Sqlite, then ensure the database.json is pointing at the correct DB type \ No newline at end of file diff --git a/src/Ombi.Store/Migrations/ExternalMySql/20191103213915_Inital.Designer.cs b/src/Ombi.Store/Migrations/ExternalMySql/20191103213915_Inital.Designer.cs new file mode 100644 index 000000000..3975c306f --- /dev/null +++ b/src/Ombi.Store/Migrations/ExternalMySql/20191103213915_Inital.Designer.cs @@ -0,0 +1,315 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Ombi.Store.Context.MySql; + +namespace Ombi.Store.Migrations.ExternalMySql +{ + [DbContext(typeof(ExternalMySqlContext))] + [Migration("20191103213915_Inital")] + partial class Inital + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Ombi.Store.Entities.CouchPotatoCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("CouchPotatoCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("EmbyId") + .IsRequired(); + + b.Property("ImdbId"); + + b.Property("ProviderId"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("EmbyContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyEpisode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("EmbyId"); + + b.Property("EpisodeNumber"); + + b.Property("ImdbId"); + + b.Property("ParentId"); + + b.Property("ProviderId"); + + b.Property("SeasonNumber"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("EmbyEpisode"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.LidarrAlbumCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("ArtistId"); + + b.Property("ForeignAlbumId"); + + b.Property("Monitored"); + + b.Property("PercentOfTracks"); + + b.Property("ReleaseDate"); + + b.Property("Title"); + + b.Property("TrackCount"); + + b.HasKey("Id"); + + b.ToTable("LidarrAlbumCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.LidarrArtistCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ArtistId"); + + b.Property("ArtistName"); + + b.Property("ForeignArtistId"); + + b.Property("Monitored"); + + b.HasKey("Id"); + + b.ToTable("LidarrArtistCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("GrandparentKey"); + + b.Property("Key"); + + b.Property("ParentKey"); + + b.Property("SeasonNumber"); + + b.Property("Title"); + + b.HasKey("Id"); + + b.HasIndex("GrandparentKey"); + + b.ToTable("PlexEpisode"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ParentKey"); + + b.Property("PlexContentId"); + + b.Property("PlexServerContentId"); + + b.Property("SeasonKey"); + + b.Property("SeasonNumber"); + + b.HasKey("Id"); + + b.HasIndex("PlexServerContentId"); + + b.ToTable("PlexSeasonsContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexServerContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("ImdbId"); + + b.Property("Key"); + + b.Property("Quality"); + + b.Property("ReleaseYear"); + + b.Property("RequestId"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("PlexServerContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.RadarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("HasFile"); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("RadarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SickRageCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SickRageCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SickRageEpisodeCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("SeasonNumber"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SickRageEpisodeCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SonarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SonarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SonarrEpisodeCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("HasFile"); + + b.Property("SeasonNumber"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SonarrEpisodeCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyEpisode", b => + { + b.HasOne("Ombi.Store.Entities.EmbyContent", "Series") + .WithMany("Episodes") + .HasForeignKey("ParentId") + .HasPrincipalKey("EmbyId"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b => + { + b.HasOne("Ombi.Store.Entities.PlexServerContent", "Series") + .WithMany("Episodes") + .HasForeignKey("GrandparentKey") + .HasPrincipalKey("Key") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.HasOne("Ombi.Store.Entities.PlexServerContent") + .WithMany("Seasons") + .HasForeignKey("PlexServerContentId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Ombi.Store/Migrations/ExternalMySql/20191103213915_Inital.cs b/src/Ombi.Store/Migrations/ExternalMySql/20191103213915_Inital.cs new file mode 100644 index 000000000..b6dc51a01 --- /dev/null +++ b/src/Ombi.Store/Migrations/ExternalMySql/20191103213915_Inital.cs @@ -0,0 +1,310 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Ombi.Store.Migrations.ExternalMySql +{ + public partial class Inital : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CouchPotatoCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + TheMovieDbId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CouchPotatoCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "EmbyContent", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Title = table.Column(nullable: true), + ProviderId = table.Column(nullable: true), + EmbyId = table.Column(nullable: false), + Type = table.Column(nullable: false), + AddedAt = table.Column(nullable: false), + ImdbId = table.Column(nullable: true), + TheMovieDbId = table.Column(nullable: true), + TvDbId = table.Column(nullable: true), + Url = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_EmbyContent", x => x.Id); + table.UniqueConstraint("AK_EmbyContent_EmbyId", x => x.EmbyId); + }); + + migrationBuilder.CreateTable( + name: "LidarrAlbumCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + ArtistId = table.Column(nullable: false), + ForeignAlbumId = table.Column(nullable: true), + TrackCount = table.Column(nullable: false), + ReleaseDate = table.Column(nullable: false), + Monitored = table.Column(nullable: false), + Title = table.Column(nullable: true), + PercentOfTracks = table.Column(nullable: false), + AddedAt = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LidarrAlbumCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "LidarrArtistCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + ArtistId = table.Column(nullable: false), + ArtistName = table.Column(nullable: true), + ForeignArtistId = table.Column(nullable: true), + Monitored = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LidarrArtistCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "PlexServerContent", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Title = table.Column(nullable: true), + ReleaseYear = table.Column(nullable: true), + ImdbId = table.Column(nullable: true), + TvDbId = table.Column(nullable: true), + TheMovieDbId = table.Column(nullable: true), + Type = table.Column(nullable: false), + Url = table.Column(nullable: true), + Key = table.Column(nullable: false), + AddedAt = table.Column(nullable: false), + Quality = table.Column(nullable: true), + RequestId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PlexServerContent", x => x.Id); + table.UniqueConstraint("AK_PlexServerContent_Key", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "RadarrCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + TheMovieDbId = table.Column(nullable: false), + HasFile = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RadarrCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SickRageCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + TvDbId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SickRageCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SickRageEpisodeCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + SeasonNumber = table.Column(nullable: false), + EpisodeNumber = table.Column(nullable: false), + TvDbId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SickRageEpisodeCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SonarrCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + TvDbId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SonarrCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SonarrEpisodeCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + SeasonNumber = table.Column(nullable: false), + EpisodeNumber = table.Column(nullable: false), + TvDbId = table.Column(nullable: false), + HasFile = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SonarrEpisodeCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "EmbyEpisode", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Title = table.Column(nullable: true), + EmbyId = table.Column(nullable: true), + EpisodeNumber = table.Column(nullable: false), + SeasonNumber = table.Column(nullable: false), + ParentId = table.Column(nullable: true), + ProviderId = table.Column(nullable: true), + AddedAt = table.Column(nullable: false), + TvDbId = table.Column(nullable: true), + ImdbId = table.Column(nullable: true), + TheMovieDbId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_EmbyEpisode", x => x.Id); + table.ForeignKey( + name: "FK_EmbyEpisode_EmbyContent_ParentId", + column: x => x.ParentId, + principalTable: "EmbyContent", + principalColumn: "EmbyId", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "PlexEpisode", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + EpisodeNumber = table.Column(nullable: false), + SeasonNumber = table.Column(nullable: false), + Key = table.Column(nullable: false), + Title = table.Column(nullable: true), + ParentKey = table.Column(nullable: false), + GrandparentKey = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PlexEpisode", x => x.Id); + table.ForeignKey( + name: "FK_PlexEpisode_PlexServerContent_GrandparentKey", + column: x => x.GrandparentKey, + principalTable: "PlexServerContent", + principalColumn: "Key", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PlexSeasonsContent", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + PlexContentId = table.Column(nullable: false), + SeasonNumber = table.Column(nullable: false), + SeasonKey = table.Column(nullable: false), + ParentKey = table.Column(nullable: false), + PlexServerContentId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PlexSeasonsContent", x => x.Id); + table.ForeignKey( + name: "FK_PlexSeasonsContent_PlexServerContent_PlexServerContentId", + column: x => x.PlexServerContentId, + principalTable: "PlexServerContent", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_EmbyEpisode_ParentId", + table: "EmbyEpisode", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_PlexEpisode_GrandparentKey", + table: "PlexEpisode", + column: "GrandparentKey"); + + migrationBuilder.CreateIndex( + name: "IX_PlexSeasonsContent_PlexServerContentId", + table: "PlexSeasonsContent", + column: "PlexServerContentId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CouchPotatoCache"); + + migrationBuilder.DropTable( + name: "EmbyEpisode"); + + migrationBuilder.DropTable( + name: "LidarrAlbumCache"); + + migrationBuilder.DropTable( + name: "LidarrArtistCache"); + + migrationBuilder.DropTable( + name: "PlexEpisode"); + + migrationBuilder.DropTable( + name: "PlexSeasonsContent"); + + migrationBuilder.DropTable( + name: "RadarrCache"); + + migrationBuilder.DropTable( + name: "SickRageCache"); + + migrationBuilder.DropTable( + name: "SickRageEpisodeCache"); + + migrationBuilder.DropTable( + name: "SonarrCache"); + + migrationBuilder.DropTable( + name: "SonarrEpisodeCache"); + + migrationBuilder.DropTable( + name: "EmbyContent"); + + migrationBuilder.DropTable( + name: "PlexServerContent"); + } + } +} diff --git a/src/Ombi.Store/Migrations/ExternalMySql/ExternalMySqlContextModelSnapshot.cs b/src/Ombi.Store/Migrations/ExternalMySql/ExternalMySqlContextModelSnapshot.cs new file mode 100644 index 000000000..c9ca6fc74 --- /dev/null +++ b/src/Ombi.Store/Migrations/ExternalMySql/ExternalMySqlContextModelSnapshot.cs @@ -0,0 +1,313 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Ombi.Store.Context.MySql; + +namespace Ombi.Store.Migrations.ExternalMySql +{ + [DbContext(typeof(ExternalMySqlContext))] + partial class ExternalMySqlContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Ombi.Store.Entities.CouchPotatoCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("CouchPotatoCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("EmbyId") + .IsRequired(); + + b.Property("ImdbId"); + + b.Property("ProviderId"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("EmbyContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyEpisode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("EmbyId"); + + b.Property("EpisodeNumber"); + + b.Property("ImdbId"); + + b.Property("ParentId"); + + b.Property("ProviderId"); + + b.Property("SeasonNumber"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("EmbyEpisode"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.LidarrAlbumCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("ArtistId"); + + b.Property("ForeignAlbumId"); + + b.Property("Monitored"); + + b.Property("PercentOfTracks"); + + b.Property("ReleaseDate"); + + b.Property("Title"); + + b.Property("TrackCount"); + + b.HasKey("Id"); + + b.ToTable("LidarrAlbumCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.LidarrArtistCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ArtistId"); + + b.Property("ArtistName"); + + b.Property("ForeignArtistId"); + + b.Property("Monitored"); + + b.HasKey("Id"); + + b.ToTable("LidarrArtistCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("GrandparentKey"); + + b.Property("Key"); + + b.Property("ParentKey"); + + b.Property("SeasonNumber"); + + b.Property("Title"); + + b.HasKey("Id"); + + b.HasIndex("GrandparentKey"); + + b.ToTable("PlexEpisode"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ParentKey"); + + b.Property("PlexContentId"); + + b.Property("PlexServerContentId"); + + b.Property("SeasonKey"); + + b.Property("SeasonNumber"); + + b.HasKey("Id"); + + b.HasIndex("PlexServerContentId"); + + b.ToTable("PlexSeasonsContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexServerContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("ImdbId"); + + b.Property("Key"); + + b.Property("Quality"); + + b.Property("ReleaseYear"); + + b.Property("RequestId"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("PlexServerContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.RadarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("HasFile"); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("RadarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SickRageCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SickRageCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SickRageEpisodeCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("SeasonNumber"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SickRageEpisodeCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SonarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SonarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SonarrEpisodeCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("HasFile"); + + b.Property("SeasonNumber"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SonarrEpisodeCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyEpisode", b => + { + b.HasOne("Ombi.Store.Entities.EmbyContent", "Series") + .WithMany("Episodes") + .HasForeignKey("ParentId") + .HasPrincipalKey("EmbyId"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b => + { + b.HasOne("Ombi.Store.Entities.PlexServerContent", "Series") + .WithMany("Episodes") + .HasForeignKey("GrandparentKey") + .HasPrincipalKey("Key") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.HasOne("Ombi.Store.Entities.PlexServerContent") + .WithMany("Seasons") + .HasForeignKey("PlexServerContentId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Ombi.Store/Migrations/ExternalSqlite/20191103205133_Inital.Designer.cs b/src/Ombi.Store/Migrations/ExternalSqlite/20191103205133_Inital.Designer.cs new file mode 100644 index 000000000..0aae33972 --- /dev/null +++ b/src/Ombi.Store/Migrations/ExternalSqlite/20191103205133_Inital.Designer.cs @@ -0,0 +1,314 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Ombi.Store.Context.Sqlite; + +namespace Ombi.Store.Migrations.ExternalSqlite +{ + [DbContext(typeof(ExternalSqliteContext))] + [Migration("20191103205133_Inital")] + partial class Inital + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079"); + + modelBuilder.Entity("Ombi.Store.Entities.CouchPotatoCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("CouchPotatoCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("EmbyId") + .IsRequired(); + + b.Property("ImdbId"); + + b.Property("ProviderId"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("EmbyContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyEpisode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("EmbyId"); + + b.Property("EpisodeNumber"); + + b.Property("ImdbId"); + + b.Property("ParentId"); + + b.Property("ProviderId"); + + b.Property("SeasonNumber"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("EmbyEpisode"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.LidarrAlbumCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("ArtistId"); + + b.Property("ForeignAlbumId"); + + b.Property("Monitored"); + + b.Property("PercentOfTracks"); + + b.Property("ReleaseDate"); + + b.Property("Title"); + + b.Property("TrackCount"); + + b.HasKey("Id"); + + b.ToTable("LidarrAlbumCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.LidarrArtistCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ArtistId"); + + b.Property("ArtistName"); + + b.Property("ForeignArtistId"); + + b.Property("Monitored"); + + b.HasKey("Id"); + + b.ToTable("LidarrArtistCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("GrandparentKey"); + + b.Property("Key"); + + b.Property("ParentKey"); + + b.Property("SeasonNumber"); + + b.Property("Title"); + + b.HasKey("Id"); + + b.HasIndex("GrandparentKey"); + + b.ToTable("PlexEpisode"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ParentKey"); + + b.Property("PlexContentId"); + + b.Property("PlexServerContentId"); + + b.Property("SeasonKey"); + + b.Property("SeasonNumber"); + + b.HasKey("Id"); + + b.HasIndex("PlexServerContentId"); + + b.ToTable("PlexSeasonsContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexServerContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("ImdbId"); + + b.Property("Key"); + + b.Property("Quality"); + + b.Property("ReleaseYear"); + + b.Property("RequestId"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("PlexServerContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.RadarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("HasFile"); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("RadarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SickRageCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SickRageCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SickRageEpisodeCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("SeasonNumber"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SickRageEpisodeCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SonarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SonarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SonarrEpisodeCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("HasFile"); + + b.Property("SeasonNumber"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SonarrEpisodeCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyEpisode", b => + { + b.HasOne("Ombi.Store.Entities.EmbyContent", "Series") + .WithMany("Episodes") + .HasForeignKey("ParentId") + .HasPrincipalKey("EmbyId"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b => + { + b.HasOne("Ombi.Store.Entities.PlexServerContent", "Series") + .WithMany("Episodes") + .HasForeignKey("GrandparentKey") + .HasPrincipalKey("Key") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.HasOne("Ombi.Store.Entities.PlexServerContent") + .WithMany("Seasons") + .HasForeignKey("PlexServerContentId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Ombi.Store/Migrations/ExternalSqlite/20191103205133_Inital.cs b/src/Ombi.Store/Migrations/ExternalSqlite/20191103205133_Inital.cs new file mode 100644 index 000000000..35b56b638 --- /dev/null +++ b/src/Ombi.Store/Migrations/ExternalSqlite/20191103205133_Inital.cs @@ -0,0 +1,309 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Ombi.Store.Migrations.ExternalSqlite +{ + public partial class Inital : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CouchPotatoCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + TheMovieDbId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CouchPotatoCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "EmbyContent", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Title = table.Column(nullable: true), + ProviderId = table.Column(nullable: true), + EmbyId = table.Column(nullable: false), + Type = table.Column(nullable: false), + AddedAt = table.Column(nullable: false), + ImdbId = table.Column(nullable: true), + TheMovieDbId = table.Column(nullable: true), + TvDbId = table.Column(nullable: true), + Url = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_EmbyContent", x => x.Id); + table.UniqueConstraint("AK_EmbyContent_EmbyId", x => x.EmbyId); + }); + + migrationBuilder.CreateTable( + name: "LidarrAlbumCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ArtistId = table.Column(nullable: false), + ForeignAlbumId = table.Column(nullable: true), + TrackCount = table.Column(nullable: false), + ReleaseDate = table.Column(nullable: false), + Monitored = table.Column(nullable: false), + Title = table.Column(nullable: true), + PercentOfTracks = table.Column(nullable: false), + AddedAt = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LidarrAlbumCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "LidarrArtistCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + ArtistId = table.Column(nullable: false), + ArtistName = table.Column(nullable: true), + ForeignArtistId = table.Column(nullable: true), + Monitored = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_LidarrArtistCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "PlexServerContent", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Title = table.Column(nullable: true), + ReleaseYear = table.Column(nullable: true), + ImdbId = table.Column(nullable: true), + TvDbId = table.Column(nullable: true), + TheMovieDbId = table.Column(nullable: true), + Type = table.Column(nullable: false), + Url = table.Column(nullable: true), + Key = table.Column(nullable: false), + AddedAt = table.Column(nullable: false), + Quality = table.Column(nullable: true), + RequestId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PlexServerContent", x => x.Id); + table.UniqueConstraint("AK_PlexServerContent_Key", x => x.Key); + }); + + migrationBuilder.CreateTable( + name: "RadarrCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + TheMovieDbId = table.Column(nullable: false), + HasFile = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RadarrCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SickRageCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + TvDbId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SickRageCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SickRageEpisodeCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + SeasonNumber = table.Column(nullable: false), + EpisodeNumber = table.Column(nullable: false), + TvDbId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SickRageEpisodeCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SonarrCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + TvDbId = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SonarrCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SonarrEpisodeCache", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + SeasonNumber = table.Column(nullable: false), + EpisodeNumber = table.Column(nullable: false), + TvDbId = table.Column(nullable: false), + HasFile = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SonarrEpisodeCache", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "EmbyEpisode", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Title = table.Column(nullable: true), + EmbyId = table.Column(nullable: true), + EpisodeNumber = table.Column(nullable: false), + SeasonNumber = table.Column(nullable: false), + ParentId = table.Column(nullable: true), + ProviderId = table.Column(nullable: true), + AddedAt = table.Column(nullable: false), + TvDbId = table.Column(nullable: true), + ImdbId = table.Column(nullable: true), + TheMovieDbId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_EmbyEpisode", x => x.Id); + table.ForeignKey( + name: "FK_EmbyEpisode_EmbyContent_ParentId", + column: x => x.ParentId, + principalTable: "EmbyContent", + principalColumn: "EmbyId", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateTable( + name: "PlexEpisode", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + EpisodeNumber = table.Column(nullable: false), + SeasonNumber = table.Column(nullable: false), + Key = table.Column(nullable: false), + Title = table.Column(nullable: true), + ParentKey = table.Column(nullable: false), + GrandparentKey = table.Column(nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PlexEpisode", x => x.Id); + table.ForeignKey( + name: "FK_PlexEpisode_PlexServerContent_GrandparentKey", + column: x => x.GrandparentKey, + principalTable: "PlexServerContent", + principalColumn: "Key", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PlexSeasonsContent", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + PlexContentId = table.Column(nullable: false), + SeasonNumber = table.Column(nullable: false), + SeasonKey = table.Column(nullable: false), + ParentKey = table.Column(nullable: false), + PlexServerContentId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_PlexSeasonsContent", x => x.Id); + table.ForeignKey( + name: "FK_PlexSeasonsContent_PlexServerContent_PlexServerContentId", + column: x => x.PlexServerContentId, + principalTable: "PlexServerContent", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_EmbyEpisode_ParentId", + table: "EmbyEpisode", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_PlexEpisode_GrandparentKey", + table: "PlexEpisode", + column: "GrandparentKey"); + + migrationBuilder.CreateIndex( + name: "IX_PlexSeasonsContent_PlexServerContentId", + table: "PlexSeasonsContent", + column: "PlexServerContentId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CouchPotatoCache"); + + migrationBuilder.DropTable( + name: "EmbyEpisode"); + + migrationBuilder.DropTable( + name: "LidarrAlbumCache"); + + migrationBuilder.DropTable( + name: "LidarrArtistCache"); + + migrationBuilder.DropTable( + name: "PlexEpisode"); + + migrationBuilder.DropTable( + name: "PlexSeasonsContent"); + + migrationBuilder.DropTable( + name: "RadarrCache"); + + migrationBuilder.DropTable( + name: "SickRageCache"); + + migrationBuilder.DropTable( + name: "SickRageEpisodeCache"); + + migrationBuilder.DropTable( + name: "SonarrCache"); + + migrationBuilder.DropTable( + name: "SonarrEpisodeCache"); + + migrationBuilder.DropTable( + name: "EmbyContent"); + + migrationBuilder.DropTable( + name: "PlexServerContent"); + } + } +} diff --git a/src/Ombi.Store/Migrations/ExternalSqlite/ExternalSqliteContextModelSnapshot.cs b/src/Ombi.Store/Migrations/ExternalSqlite/ExternalSqliteContextModelSnapshot.cs new file mode 100644 index 000000000..86e292e2f --- /dev/null +++ b/src/Ombi.Store/Migrations/ExternalSqlite/ExternalSqliteContextModelSnapshot.cs @@ -0,0 +1,312 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Ombi.Store.Context.Sqlite; + +namespace Ombi.Store.Migrations.ExternalSqlite +{ + [DbContext(typeof(ExternalSqliteContext))] + partial class ExternalSqliteContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079"); + + modelBuilder.Entity("Ombi.Store.Entities.CouchPotatoCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("CouchPotatoCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("EmbyId") + .IsRequired(); + + b.Property("ImdbId"); + + b.Property("ProviderId"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("EmbyContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyEpisode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("EmbyId"); + + b.Property("EpisodeNumber"); + + b.Property("ImdbId"); + + b.Property("ParentId"); + + b.Property("ProviderId"); + + b.Property("SeasonNumber"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("EmbyEpisode"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.LidarrAlbumCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("ArtistId"); + + b.Property("ForeignAlbumId"); + + b.Property("Monitored"); + + b.Property("PercentOfTracks"); + + b.Property("ReleaseDate"); + + b.Property("Title"); + + b.Property("TrackCount"); + + b.HasKey("Id"); + + b.ToTable("LidarrAlbumCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.LidarrArtistCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ArtistId"); + + b.Property("ArtistName"); + + b.Property("ForeignArtistId"); + + b.Property("Monitored"); + + b.HasKey("Id"); + + b.ToTable("LidarrArtistCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("GrandparentKey"); + + b.Property("Key"); + + b.Property("ParentKey"); + + b.Property("SeasonNumber"); + + b.Property("Title"); + + b.HasKey("Id"); + + b.HasIndex("GrandparentKey"); + + b.ToTable("PlexEpisode"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ParentKey"); + + b.Property("PlexContentId"); + + b.Property("PlexServerContentId"); + + b.Property("SeasonKey"); + + b.Property("SeasonNumber"); + + b.HasKey("Id"); + + b.HasIndex("PlexServerContentId"); + + b.ToTable("PlexSeasonsContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexServerContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("ImdbId"); + + b.Property("Key"); + + b.Property("Quality"); + + b.Property("ReleaseYear"); + + b.Property("RequestId"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("PlexServerContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.RadarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("HasFile"); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("RadarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SickRageCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SickRageCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SickRageEpisodeCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("SeasonNumber"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SickRageEpisodeCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SonarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SonarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SonarrEpisodeCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("HasFile"); + + b.Property("SeasonNumber"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SonarrEpisodeCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyEpisode", b => + { + b.HasOne("Ombi.Store.Entities.EmbyContent", "Series") + .WithMany("Episodes") + .HasForeignKey("ParentId") + .HasPrincipalKey("EmbyId"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b => + { + b.HasOne("Ombi.Store.Entities.PlexServerContent", "Series") + .WithMany("Episodes") + .HasForeignKey("GrandparentKey") + .HasPrincipalKey("Key") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.HasOne("Ombi.Store.Entities.PlexServerContent") + .WithMany("Seasons") + .HasForeignKey("PlexServerContentId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Ombi.Store/Migrations/OmbiMySql/20191102235852_Inital.Designer.cs b/src/Ombi.Store/Migrations/OmbiMySql/20191102235852_Inital.Designer.cs index 2f368a735..f72e34766 100644 --- a/src/Ombi.Store/Migrations/OmbiMySql/20191102235852_Inital.Designer.cs +++ b/src/Ombi.Store/Migrations/OmbiMySql/20191102235852_Inital.Designer.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Ombi.Store.Context; +using Ombi.Store.Context.MySql; namespace Ombi.Store.Migrations.OmbiMySql { diff --git a/src/Ombi.Store/Migrations/OmbiMySql/OmbiMySqlContextModelSnapshot.cs b/src/Ombi.Store/Migrations/OmbiMySql/OmbiMySqlContextModelSnapshot.cs index 161e882ea..f7e598984 100644 --- a/src/Ombi.Store/Migrations/OmbiMySql/OmbiMySqlContextModelSnapshot.cs +++ b/src/Ombi.Store/Migrations/OmbiMySql/OmbiMySqlContextModelSnapshot.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Ombi.Store.Context; +using Ombi.Store.Context.MySql; namespace Ombi.Store.Migrations.OmbiMySql { diff --git a/src/Ombi.Store/Migrations/OmbiSqlite/20191102235658_Inital.Designer.cs b/src/Ombi.Store/Migrations/OmbiSqlite/20191102235658_Inital.Designer.cs index f61ff54f6..e5d2c302e 100644 --- a/src/Ombi.Store/Migrations/OmbiSqlite/20191102235658_Inital.Designer.cs +++ b/src/Ombi.Store/Migrations/OmbiSqlite/20191102235658_Inital.Designer.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Ombi.Store.Context; +using Ombi.Store.Context.Sqlite; namespace Ombi.Store.Migrations.OmbiSqlite { diff --git a/src/Ombi.Store/Migrations/OmbiSqlite/OmbiSqliteContextModelSnapshot.cs b/src/Ombi.Store/Migrations/OmbiSqlite/OmbiSqliteContextModelSnapshot.cs index 3365749d1..271c38300 100644 --- a/src/Ombi.Store/Migrations/OmbiSqlite/OmbiSqliteContextModelSnapshot.cs +++ b/src/Ombi.Store/Migrations/OmbiSqlite/OmbiSqliteContextModelSnapshot.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Ombi.Store.Context; +using Ombi.Store.Context.Sqlite; namespace Ombi.Store.Migrations.OmbiSqlite { diff --git a/src/Ombi.Store/Migrations/SettingsMySql/20191103205915_Inital.Designer.cs b/src/Ombi.Store/Migrations/SettingsMySql/20191103205915_Inital.Designer.cs new file mode 100644 index 000000000..1e56e9109 --- /dev/null +++ b/src/Ombi.Store/Migrations/SettingsMySql/20191103205915_Inital.Designer.cs @@ -0,0 +1,51 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Ombi.Store.Context.MySql; + +namespace Ombi.Store.Migrations.SettingsMySql +{ + [DbContext(typeof(SettingsMySqlContext))] + [Migration("20191103205915_Inital")] + partial class Inital + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Ombi.Store.Entities.ApplicationConfiguration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Type"); + + b.Property("Value"); + + b.HasKey("Id"); + + b.ToTable("ApplicationConfiguration"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Content"); + + b.Property("SettingsName"); + + b.HasKey("Id"); + + b.ToTable("GlobalSettings"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Ombi.Store/Migrations/SettingsMySql/20191103205915_Inital.cs b/src/Ombi.Store/Migrations/SettingsMySql/20191103205915_Inital.cs new file mode 100644 index 000000000..1639ed945 --- /dev/null +++ b/src/Ombi.Store/Migrations/SettingsMySql/20191103205915_Inital.cs @@ -0,0 +1,48 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Ombi.Store.Migrations.SettingsMySql +{ + public partial class Inital : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ApplicationConfiguration", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Type = table.Column(nullable: false), + Value = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ApplicationConfiguration", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "GlobalSettings", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Content = table.Column(nullable: true), + SettingsName = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_GlobalSettings", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ApplicationConfiguration"); + + migrationBuilder.DropTable( + name: "GlobalSettings"); + } + } +} diff --git a/src/Ombi.Store/Migrations/SettingsMySql/SettingsMySqlContextModelSnapshot.cs b/src/Ombi.Store/Migrations/SettingsMySql/SettingsMySqlContextModelSnapshot.cs new file mode 100644 index 000000000..a3dab1d12 --- /dev/null +++ b/src/Ombi.Store/Migrations/SettingsMySql/SettingsMySqlContextModelSnapshot.cs @@ -0,0 +1,49 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Ombi.Store.Context.MySql; + +namespace Ombi.Store.Migrations.SettingsMySql +{ + [DbContext(typeof(SettingsMySqlContext))] + partial class SettingsMySqlContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Ombi.Store.Entities.ApplicationConfiguration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Type"); + + b.Property("Value"); + + b.HasKey("Id"); + + b.ToTable("ApplicationConfiguration"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Content"); + + b.Property("SettingsName"); + + b.HasKey("Id"); + + b.ToTable("GlobalSettings"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Ombi.Store/Migrations/SettingsSqlite/20191103205204_Inital.Designer.cs b/src/Ombi.Store/Migrations/SettingsSqlite/20191103205204_Inital.Designer.cs new file mode 100644 index 000000000..7cd132758 --- /dev/null +++ b/src/Ombi.Store/Migrations/SettingsSqlite/20191103205204_Inital.Designer.cs @@ -0,0 +1,50 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Ombi.Store.Context.Sqlite; + +namespace Ombi.Store.Migrations.SettingsSqlite +{ + [DbContext(typeof(SettingsSqliteContext))] + [Migration("20191103205204_Inital")] + partial class Inital + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079"); + + modelBuilder.Entity("Ombi.Store.Entities.ApplicationConfiguration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Type"); + + b.Property("Value"); + + b.HasKey("Id"); + + b.ToTable("ApplicationConfiguration"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Content"); + + b.Property("SettingsName"); + + b.HasKey("Id"); + + b.ToTable("GlobalSettings"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Ombi.Store/Migrations/SettingsSqlite/20191103205204_Inital.cs b/src/Ombi.Store/Migrations/SettingsSqlite/20191103205204_Inital.cs new file mode 100644 index 000000000..c4883a99b --- /dev/null +++ b/src/Ombi.Store/Migrations/SettingsSqlite/20191103205204_Inital.cs @@ -0,0 +1,47 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Ombi.Store.Migrations.SettingsSqlite +{ + public partial class Inital : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ApplicationConfiguration", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Type = table.Column(nullable: false), + Value = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ApplicationConfiguration", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "GlobalSettings", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Content = table.Column(nullable: true), + SettingsName = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_GlobalSettings", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ApplicationConfiguration"); + + migrationBuilder.DropTable( + name: "GlobalSettings"); + } + } +} diff --git a/src/Ombi.Store/Migrations/SettingsSqlite/SettingsSqliteContextModelSnapshot.cs b/src/Ombi.Store/Migrations/SettingsSqlite/SettingsSqliteContextModelSnapshot.cs new file mode 100644 index 000000000..17b521507 --- /dev/null +++ b/src/Ombi.Store/Migrations/SettingsSqlite/SettingsSqliteContextModelSnapshot.cs @@ -0,0 +1,48 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Ombi.Store.Context.Sqlite; + +namespace Ombi.Store.Migrations.SettingsSqlite +{ + [DbContext(typeof(SettingsSqliteContext))] + partial class SettingsSqliteContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079"); + + modelBuilder.Entity("Ombi.Store.Entities.ApplicationConfiguration", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Type"); + + b.Property("Value"); + + b.HasKey("Id"); + + b.ToTable("ApplicationConfiguration"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Content"); + + b.Property("SettingsName"); + + b.HasKey("Id"); + + b.ToTable("GlobalSettings"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Ombi.Store/Repository/ApplicationConfigRepository.cs b/src/Ombi.Store/Repository/ApplicationConfigRepository.cs index 31ec3313c..c05b91b45 100644 --- a/src/Ombi.Store/Repository/ApplicationConfigRepository.cs +++ b/src/Ombi.Store/Repository/ApplicationConfigRepository.cs @@ -8,12 +8,12 @@ namespace Ombi.Store.Repository { public class ApplicationConfigRepository : IApplicationConfigRepository { - public ApplicationConfigRepository(ISettingsContext ctx) + public ApplicationConfigRepository(SettingsContext ctx) { Ctx = ctx; } - private ISettingsContext Ctx { get; } + private SettingsContext Ctx { get; } public Task GetAsync(ConfigurationTypes type) { diff --git a/src/Ombi.Store/Repository/SettingsJsonRepository.cs b/src/Ombi.Store/Repository/SettingsJsonRepository.cs index 622e32997..cceb8cdec 100644 --- a/src/Ombi.Store/Repository/SettingsJsonRepository.cs +++ b/src/Ombi.Store/Repository/SettingsJsonRepository.cs @@ -12,13 +12,13 @@ namespace Ombi.Store.Repository { public class SettingsJsonRepository : ISettingsRepository { - public SettingsJsonRepository(ISettingsContext ctx, ICacheService mem) + public SettingsJsonRepository(SettingsContext ctx, ICacheService mem) { Db = ctx; _cache = mem; } - private ISettingsContext Db { get; } + private SettingsContext Db { get; } private readonly ICacheService _cache; public GlobalSettings Insert(GlobalSettings entity) diff --git a/src/Ombi/Extensions/DatabaseExtensions.cs b/src/Ombi/Extensions/DatabaseExtensions.cs index 541113046..82daafff9 100644 --- a/src/Ombi/Extensions/DatabaseExtensions.cs +++ b/src/Ombi/Extensions/DatabaseExtensions.cs @@ -5,6 +5,8 @@ using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using Ombi.Helpers; using Ombi.Store.Context; +using Ombi.Store.Context.MySql; +using Ombi.Store.Context.Sqlite; using SQLitePCL; namespace Ombi.Extensions @@ -12,8 +14,8 @@ namespace Ombi.Extensions public static class DatabaseExtensions { - private const string SqliteDatabase = "Sqlite"; - private const string MySqlDatabase = "MySQL"; + public const string SqliteDatabase = "Sqlite"; + public const string MySqlDatabase = "MySQL"; public static void ConfigureDatabases(this IServiceCollection services) { @@ -36,9 +38,29 @@ namespace Ombi.Extensions services.AddDbContext(x => ConfigureMySql(x, configuration.OmbiDatabase)); break; } + + switch (configuration.ExternalDatabase.Type) + { + case var type when type.Equals(SqliteDatabase, StringComparison.InvariantCultureIgnoreCase): + services.AddDbContext(x => ConfigureSqlite(x, configuration.ExternalDatabase)); + break; + case var type when type.Equals(MySqlDatabase, StringComparison.InvariantCultureIgnoreCase): + services.AddDbContext(x => ConfigureMySql(x, configuration.ExternalDatabase)); + break; + } + + switch (configuration.SettingsDatabase.Type) + { + case var type when type.Equals(SqliteDatabase, StringComparison.InvariantCultureIgnoreCase): + services.AddDbContext(x => ConfigureSqlite(x, configuration.SettingsDatabase)); + break; + case var type when type.Equals(MySqlDatabase, StringComparison.InvariantCultureIgnoreCase): + services.AddDbContext(x => ConfigureMySql(x, configuration.SettingsDatabase)); + break; + } } - private static DatabaseConfiguration GetDatabaseConfiguration(string databaseFileLocation, string storagePath) + public static DatabaseConfiguration GetDatabaseConfiguration(string databaseFileLocation, string storagePath) { var configuration = new DatabaseConfiguration(storagePath); if (File.Exists(databaseFileLocation)) @@ -55,7 +77,7 @@ namespace Ombi.Extensions return configuration; } - private static void ConfigureSqlite(DbContextOptionsBuilder options, PerDatabaseConfiguration config) + public static void ConfigureSqlite(DbContextOptionsBuilder options, PerDatabaseConfiguration config) { SQLitePCL.Batteries.Init(); SQLitePCL.raw.sqlite3_config(raw.SQLITE_CONFIG_MULTITHREAD); @@ -63,12 +85,12 @@ namespace Ombi.Extensions options.UseSqlite(config.ConnectionString); } - private static void ConfigureMySql(DbContextOptionsBuilder options, PerDatabaseConfiguration config) + public static void ConfigureMySql(DbContextOptionsBuilder options, PerDatabaseConfiguration config) { options.UseMySql(config.ConnectionString); } - private class DatabaseConfiguration + public class DatabaseConfiguration { public DatabaseConfiguration() { @@ -78,15 +100,15 @@ namespace Ombi.Extensions public DatabaseConfiguration(string defaultSqlitePath) { OmbiDatabase = new PerDatabaseConfiguration(SqliteDatabase, $"Data Source={Path.Combine(defaultSqlitePath, "Ombi.db")}"); - SettingsDatabase = new PerDatabaseConfiguration(SqliteDatabase, $"Data Source={Path.Combine(defaultSqlitePath, "Settings.db")}"); - ExternalDatabase = new PerDatabaseConfiguration(SqliteDatabase, $"Data Source={Path.Combine(defaultSqlitePath, "External.db")}"); + SettingsDatabase = new PerDatabaseConfiguration(SqliteDatabase, $"Data Source={Path.Combine(defaultSqlitePath, "OmbiSettings.db")}"); + ExternalDatabase = new PerDatabaseConfiguration(SqliteDatabase, $"Data Source={Path.Combine(defaultSqlitePath, "OmbiExternal.db")}"); } public PerDatabaseConfiguration OmbiDatabase { get; set; } public PerDatabaseConfiguration SettingsDatabase { get; set; } public PerDatabaseConfiguration ExternalDatabase { get; set; } } - private class PerDatabaseConfiguration + public class PerDatabaseConfiguration { public PerDatabaseConfiguration(string type, string connectionString) { diff --git a/src/Ombi/Program.cs b/src/Ombi/Program.cs index 7eecf0b8e..8841d1fa8 100644 --- a/src/Ombi/Program.cs +++ b/src/Ombi/Program.cs @@ -9,13 +9,18 @@ using CommandLine; using CommandLine.Text; using Microsoft.AspNetCore; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Ombi.Extensions; using Ombi.Helpers; +using Ombi.Store.Context.MySql; +using Ombi.Store.Context.Sqlite; namespace Ombi { public class Program { private static string UrlArgs { get; set; } + public static void Main(string[] args) { Console.Title = "Ombi"; @@ -51,71 +56,79 @@ namespace Ombi // Check if we need to migrate the settings DeleteSchedules(); //CheckAndMigrate(); - var ctx = new SettingsContext(); - var config = ctx.ApplicationConfigurations.ToList(); - var url = config.FirstOrDefault(x => x.Type == ConfigurationTypes.Url); - var dbBaseUrl = config.FirstOrDefault(x => x.Type == ConfigurationTypes.BaseUrl); - if (url == null) + + var services = new ServiceCollection(); + services.ConfigureDatabases(); + using (var provider = services.BuildServiceProvider()) { - url = new ApplicationConfiguration - { - Type = ConfigurationTypes.Url, - Value = "http://*:5000" - }; - using (var tran = ctx.Database.BeginTransaction()) - { - ctx.ApplicationConfigurations.Add(url); - ctx.SaveChanges(); - tran.Commit(); - } + var settingsDb = provider.GetRequiredService(); - urlValue = url.Value; - } - if (!url.Value.Equals(host)) - { - url.Value = UrlArgs; - - using (var tran = ctx.Database.BeginTransaction()) + var config = settingsDb.ApplicationConfigurations.ToList(); + var url = config.FirstOrDefault(x => x.Type == ConfigurationTypes.Url); + var dbBaseUrl = config.FirstOrDefault(x => x.Type == ConfigurationTypes.BaseUrl); + if (url == null) { - ctx.SaveChanges(); - tran.Commit(); - } - - urlValue = url.Value; - } - - if (dbBaseUrl == null) - { - if (baseUrl.HasValue() && baseUrl.StartsWith("/")) - { - dbBaseUrl = new ApplicationConfiguration + url = new ApplicationConfiguration { - Type = ConfigurationTypes.BaseUrl, - Value = baseUrl + Type = ConfigurationTypes.Url, + Value = "http://*:5000" }; - - using (var tran = ctx.Database.BeginTransaction()) + using (var tran = settingsDb.Database.BeginTransaction()) { - ctx.ApplicationConfigurations.Add(dbBaseUrl); - ctx.SaveChanges(); + settingsDb.ApplicationConfigurations.Add(url); + settingsDb.SaveChanges(); + tran.Commit(); + } + + urlValue = url.Value; + } + + if (!url.Value.Equals(host)) + { + url.Value = UrlArgs; + + using (var tran = settingsDb.Database.BeginTransaction()) + { + settingsDb.SaveChanges(); + tran.Commit(); + } + + urlValue = url.Value; + } + + if (dbBaseUrl == null) + { + if (baseUrl.HasValue() && baseUrl.StartsWith("/")) + { + dbBaseUrl = new ApplicationConfiguration + { + Type = ConfigurationTypes.BaseUrl, + Value = baseUrl + }; + + using (var tran = settingsDb.Database.BeginTransaction()) + { + settingsDb.ApplicationConfigurations.Add(dbBaseUrl); + settingsDb.SaveChanges(); + tran.Commit(); + } + } + } + else if (baseUrl.HasValue() && !baseUrl.Equals(dbBaseUrl.Value)) + { + dbBaseUrl.Value = baseUrl; + + using (var tran = settingsDb.Database.BeginTransaction()) + { + settingsDb.SaveChanges(); tran.Commit(); } } + + Console.WriteLine($"We are running on {urlValue}"); + + CreateWebHostBuilder(args).Build().Run(); } - else if (baseUrl.HasValue() && !baseUrl.Equals(dbBaseUrl.Value)) - { - dbBaseUrl.Value = baseUrl; - - using (var tran = ctx.Database.BeginTransaction()) - { - ctx.SaveChanges(); - tran.Commit(); - } - } - - Console.WriteLine($"We are running on {urlValue}"); - - CreateWebHostBuilder(args).Build().Run(); } private static void DeleteSchedules() @@ -132,157 +145,6 @@ namespace Ombi } } - ///// - ///// This is to remove the Settings from the Ombi.db to the "new" - ///// OmbiSettings.db - ///// - ///// Ombi is hitting a limitation with SQLite where there is a lot of database activity - ///// and SQLite does not handle concurrency at all, causing db locks. - ///// - ///// Splitting it all out into it's own DB helps with this. - ///// - //private static void CheckAndMigrate() - //{ - // var doneGlobal = false; - // var doneConfig = false; - // var ombi = new OmbiContext(); - // var settings = new SettingsContext(); - - // try - // { - - // using (var tran = settings.Database.BeginTransaction()) - // { - // if (ombi.Settings.Any() && !settings.Settings.Any()) - // { - // // OK migrate it! - // var allSettings = ombi.Settings.ToList(); - // settings.Settings.AddRange(allSettings); - // doneGlobal = true; - // } - - // // Check for any application settings - - // if (ombi.ApplicationConfigurations.Any() && !settings.ApplicationConfigurations.Any()) - // { - // // OK migrate it! - // var allSettings = ombi.ApplicationConfigurations.ToList(); - // settings.ApplicationConfigurations.AddRange(allSettings); - // doneConfig = true; - // } - - // settings.SaveChanges(); - // tran.Commit(); - // } - // } - // catch (Exception e) - // { - // Console.WriteLine(e); - // throw; - // } - - - // using (var tran = ombi.Database.BeginTransaction()) - // { - // // Now delete the old stuff - // if (doneGlobal) - // ombi.Database.ExecuteSqlCommand("DELETE FROM GlobalSettings"); - // if (doneConfig) - // ombi.Database.ExecuteSqlCommand("DELETE FROM ApplicationConfiguration"); - // tran.Commit(); - // } - - // // Now migrate all the external stuff - // var external = new ExternalContext(); - - // try - // { - - // using (var tran = external.Database.BeginTransaction()) - // { - // if (ombi.PlexEpisode.Any()) - // { - // external.PlexEpisode.AddRange(ombi.PlexEpisode.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM PlexEpisode"); - // } - - // if (ombi.PlexSeasonsContent.Any()) - // { - // external.PlexSeasonsContent.AddRange(ombi.PlexSeasonsContent.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM PlexSeasonsContent"); - // } - - // if (ombi.PlexServerContent.Any()) - // { - // external.PlexServerContent.AddRange(ombi.PlexServerContent.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM PlexServerContent"); - // } - - // if (ombi.EmbyEpisode.Any()) - // { - // external.EmbyEpisode.AddRange(ombi.EmbyEpisode.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM EmbyEpisode"); - // } - - // if (ombi.EmbyContent.Any()) - // { - // external.EmbyContent.AddRange(ombi.EmbyContent.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM EmbyContent"); - // } - - // if (ombi.RadarrCache.Any()) - // { - // external.RadarrCache.AddRange(ombi.RadarrCache.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM RadarrCache"); - // } - - // if (ombi.SonarrCache.Any()) - // { - // external.SonarrCache.AddRange(ombi.SonarrCache.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM SonarrCache"); - // } - - // if (ombi.LidarrAlbumCache.Any()) - // { - // external.LidarrAlbumCache.AddRange(ombi.LidarrAlbumCache.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM LidarrAlbumCache"); - // } - - // if (ombi.LidarrArtistCache.Any()) - // { - // external.LidarrArtistCache.AddRange(ombi.LidarrArtistCache.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM LidarrArtistCache"); - // } - - // if (ombi.SickRageEpisodeCache.Any()) - // { - // external.SickRageEpisodeCache.AddRange(ombi.SickRageEpisodeCache.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM SickRageEpisodeCache"); - // } - - // if (ombi.SickRageCache.Any()) - // { - // external.SickRageCache.AddRange(ombi.SickRageCache.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM SickRageCache"); - // } - - // if (ombi.CouchPotatoCache.Any()) - // { - // external.CouchPotatoCache.AddRange(ombi.CouchPotatoCache.ToList()); - // ombi.Database.ExecuteSqlCommand("DELETE FROM CouchPotatoCache"); - // } - - // external.SaveChanges(); - // tran.Commit(); - // } - // } - // catch (Exception e) - // { - // Console.WriteLine(e); - // throw; - // } - //} - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup() diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index 3dd7f1136..f713fe31b 100755 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -192,10 +192,8 @@ namespace Ombi //var jobSetup = app.ApplicationServices.GetService(); //jobSetup.Setup(); ctx.Seed(); - var settingsctx = serviceProvider.GetService(); - var externalctx = serviceProvider.GetService(); + var settingsctx = serviceProvider.GetService(); settingsctx.Seed(); - externalctx.Seed(); var provider = new FileExtensionContentTypeProvider { Mappings = { [".map"] = "application/octet-stream" } };