From 37aca4e42333116549044e587a38e309739aa50f Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 2 Nov 2019 22:49:14 +0000 Subject: [PATCH] Got the new DB structure in place --- src/Ombi.DependencyInjection/IocExtensions.cs | 4 +- src/Ombi.Store/Context/IOmbiContext.cs | 44 --- src/Ombi.Store/Context/OmbiContext.cs | 46 +-- src/Ombi.Store/Context/OmbiSqliteContext.cs | 35 ++ src/Ombi.Store/Repository/AuditRepository.cs | 4 +- src/Ombi.Store/Repository/BaseRepository.cs | 2 +- .../Repository/EmbyContentRepository.cs | 4 +- .../Repository/ExternalRepository.cs | 4 +- .../NotificationTemplatesRepository.cs | 4 +- .../Repository/PlexContentRepository.cs | 4 +- src/Ombi.Store/Repository/Repository.cs | 4 +- .../Requests/ITvRequestRepository.cs | 2 +- .../Requests/MovieRequestRepository.cs | 4 +- .../Requests/MusicRequestRepository.cs | 4 +- .../Requests/TvRequestRepository.cs | 6 +- src/Ombi.Store/Repository/TokenRepository.cs | 6 +- src/Ombi.Store/Repository/UserRepository.cs | 4 +- src/Ombi/DatabaseExtensions.cs | 26 ++ src/Ombi/Ombi.csproj | 1 + src/Ombi/Program.cs | 302 +++++++++--------- src/Ombi/Startup.cs | 4 +- 21 files changed, 257 insertions(+), 257 deletions(-) delete mode 100644 src/Ombi.Store/Context/IOmbiContext.cs create mode 100644 src/Ombi.Store/Context/OmbiSqliteContext.cs create mode 100644 src/Ombi/DatabaseExtensions.cs diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index 3d54e5a67..38cb51acd 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -135,11 +135,11 @@ namespace Ombi.DependencyInjection } public static void RegisterStore(this IServiceCollection services) { - 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(); diff --git a/src/Ombi.Store/Context/IOmbiContext.cs b/src/Ombi.Store/Context/IOmbiContext.cs deleted file mode 100644 index a7fb3b47d..000000000 --- a/src/Ombi.Store/Context/IOmbiContext.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.ChangeTracking; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Ombi.Store.Entities; -using Ombi.Store.Entities.Requests; - -namespace Ombi.Store.Context -{ - public interface IOmbiContext : IDbContext - { - - //DbSet PlexServerContent { get; set; } - //DbSet PlexEpisode { get; set; } - DbSet Settings { get; set; } - //DbSet RadarrCache { get; set; } - //DbSet EmbyContent { get; set; } - //DbSet EmbyEpisode { get; set; } - DbSet NotificationTemplates { get; set; } - DbSet ApplicationConfigurations { get; set; } - DbSet Votes { get; set; } - void Seed(); - DbSet Audit { get; set; } - DbSet MovieRequests { get; set; } - DbSet AlbumRequests { get; set; } - DbSet TvRequests { get; set; } - DbSet ChildRequests { get; set; } - DbSet Issues { get; set; } - DbSet IssueCategories { get; set; } - DbSet Tokens { get; set; } - DbSet SonarrCache { get; set; } - //DbSet SonarrEpisodeCache { get; set; } - //DbSet CouchPotatoCache { get; set; } - //DbSet SickRageCache { get; set; } - //DbSet LidarrArtistCache { get; set; } - //DbSet LidarrAlbumCache { get; set; } - //DbSet SickRageEpisodeCache { get; set; } - DbSet RequestLogs { get; set; } - DbSet RecentlyAddedLogs { get; set; } - DbSet RequestSubscription { get; set; } - } -} \ No newline at end of file diff --git a/src/Ombi.Store/Context/OmbiContext.cs b/src/Ombi.Store/Context/OmbiContext.cs index 28b27107e..9b5c3b686 100644 --- a/src/Ombi.Store/Context/OmbiContext.cs +++ b/src/Ombi.Store/Context/OmbiContext.cs @@ -10,19 +10,28 @@ using Ombi.Store.Entities.Requests; namespace Ombi.Store.Context { - public sealed class OmbiContext : IdentityDbContext, IOmbiContext + public abstract class OmbiContext : IdentityDbContext { private static bool _created; - public OmbiContext() + protected OmbiContext(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 OmbiContext(DbContextOptions options) + : base(options) + { + } + + public DbSet NotificationTemplates { get; set; } public DbSet ApplicationConfigurations { get; set; } public DbSet PlexServerContent { get; set; } @@ -60,33 +69,6 @@ namespace Ombi.Store.Context public DbSet UserQualityProfileses { get; set; } public DbSet RequestQueue { 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, "Ombi.db")}"); - } - - 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/OmbiSqliteContext.cs b/src/Ombi.Store/Context/OmbiSqliteContext.cs new file mode 100644 index 000000000..9237ab3af --- /dev/null +++ b/src/Ombi.Store/Context/OmbiSqliteContext.cs @@ -0,0 +1,35 @@ +using Microsoft.EntityFrameworkCore; +using Ombi.Store.Entities; + +namespace Ombi.Store.Context +{ + public sealed class OmbiSqliteContext : OmbiContext + { + private static bool _created; + public OmbiSqliteContext(DbContextOptions options) : base(options) + { + if (_created) return; + + + _created = true; + Database.SetCommandTimeout(60); + Database.Migrate(); + } + + 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); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Store/Repository/AuditRepository.cs b/src/Ombi.Store/Repository/AuditRepository.cs index 858cd0eaf..2892e3e84 100644 --- a/src/Ombi.Store/Repository/AuditRepository.cs +++ b/src/Ombi.Store/Repository/AuditRepository.cs @@ -9,12 +9,12 @@ namespace Ombi.Store.Repository { public class AuditRepository : IAuditRepository { - public AuditRepository(IOmbiContext ctx) + public AuditRepository(OmbiContext ctx) { Ctx = ctx; } - private IOmbiContext Ctx { get; } + private OmbiContext Ctx { get; } public async Task Record(AuditType type, AuditArea area, string description) diff --git a/src/Ombi.Store/Repository/BaseRepository.cs b/src/Ombi.Store/Repository/BaseRepository.cs index 14b871a12..41a7eeb31 100644 --- a/src/Ombi.Store/Repository/BaseRepository.cs +++ b/src/Ombi.Store/Repository/BaseRepository.cs @@ -13,7 +13,7 @@ using Polly; namespace Ombi.Store.Repository { - public class BaseRepository : IRepository where T : Entity where U : IDbContext + public class BaseRepository : IRepository where T : Entity where U : DbContext { public BaseRepository(U ctx) { diff --git a/src/Ombi.Store/Repository/EmbyContentRepository.cs b/src/Ombi.Store/Repository/EmbyContentRepository.cs index 2ada709ab..f8743e30f 100644 --- a/src/Ombi.Store/Repository/EmbyContentRepository.cs +++ b/src/Ombi.Store/Repository/EmbyContentRepository.cs @@ -38,12 +38,12 @@ namespace Ombi.Store.Repository public class EmbyContentRepository : ExternalRepository, IEmbyContentRepository { - public EmbyContentRepository(IExternalContext db):base(db) + public EmbyContentRepository(ExternalContext db):base(db) { Db = db; } - private IExternalContext Db { get; } + private ExternalContext Db { get; } public async Task GetByImdbId(string imdbid) diff --git a/src/Ombi.Store/Repository/ExternalRepository.cs b/src/Ombi.Store/Repository/ExternalRepository.cs index d7494afd4..7c0551b8c 100644 --- a/src/Ombi.Store/Repository/ExternalRepository.cs +++ b/src/Ombi.Store/Repository/ExternalRepository.cs @@ -3,9 +3,9 @@ using Ombi.Store.Entities; namespace Ombi.Store.Repository { - public class ExternalRepository : BaseRepository, IExternalRepository where T : Entity + public class ExternalRepository : BaseRepository, IExternalRepository where T : Entity { - public ExternalRepository(IExternalContext ctx) : base(ctx) + public ExternalRepository(ExternalContext ctx) : base(ctx) { } } diff --git a/src/Ombi.Store/Repository/NotificationTemplatesRepository.cs b/src/Ombi.Store/Repository/NotificationTemplatesRepository.cs index 8f3968dc0..b226f9e08 100644 --- a/src/Ombi.Store/Repository/NotificationTemplatesRepository.cs +++ b/src/Ombi.Store/Repository/NotificationTemplatesRepository.cs @@ -11,12 +11,12 @@ namespace Ombi.Store.Repository { public class NotificationTemplatesRepository : INotificationTemplatesRepository { - public NotificationTemplatesRepository(IOmbiContext ctx) + public NotificationTemplatesRepository(OmbiContext ctx) { Db = ctx; } - private IOmbiContext Db { get; } + private OmbiContext Db { get; } public IQueryable All() { diff --git a/src/Ombi.Store/Repository/PlexContentRepository.cs b/src/Ombi.Store/Repository/PlexContentRepository.cs index 37275a47c..1d53874a1 100644 --- a/src/Ombi.Store/Repository/PlexContentRepository.cs +++ b/src/Ombi.Store/Repository/PlexContentRepository.cs @@ -39,12 +39,12 @@ namespace Ombi.Store.Repository public class PlexServerContentRepository : ExternalRepository, IPlexContentRepository { - public PlexServerContentRepository(IExternalContext db) : base(db) + public PlexServerContentRepository(ExternalContext db) : base(db) { Db = db; } - private IExternalContext Db { get; } + private ExternalContext Db { get; } public async Task ContentExists(string providerId) diff --git a/src/Ombi.Store/Repository/Repository.cs b/src/Ombi.Store/Repository/Repository.cs index 9d49ded58..fd634e29a 100644 --- a/src/Ombi.Store/Repository/Repository.cs +++ b/src/Ombi.Store/Repository/Repository.cs @@ -3,9 +3,9 @@ using Ombi.Store.Entities; namespace Ombi.Store.Repository { - public class Repository : BaseRepository, IRepository where T : Entity + public class Repository : BaseRepository, IRepository where T : Entity { - public Repository(IOmbiContext ctx) : base(ctx) + public Repository(OmbiContext ctx) : base(ctx) { } } diff --git a/src/Ombi.Store/Repository/Requests/ITvRequestRepository.cs b/src/Ombi.Store/Repository/Requests/ITvRequestRepository.cs index f08f7812f..1c6e4d302 100644 --- a/src/Ombi.Store/Repository/Requests/ITvRequestRepository.cs +++ b/src/Ombi.Store/Repository/Requests/ITvRequestRepository.cs @@ -8,7 +8,7 @@ namespace Ombi.Store.Repository.Requests { public interface ITvRequestRepository { - IOmbiContext Db { get; } + OmbiContext Db { get; } Task Add(TvRequests request); Task AddChild(ChildRequests request); Task Delete(TvRequests request); diff --git a/src/Ombi.Store/Repository/Requests/MovieRequestRepository.cs b/src/Ombi.Store/Repository/Requests/MovieRequestRepository.cs index 2cea81200..2df4cac0f 100644 --- a/src/Ombi.Store/Repository/Requests/MovieRequestRepository.cs +++ b/src/Ombi.Store/Repository/Requests/MovieRequestRepository.cs @@ -11,12 +11,12 @@ namespace Ombi.Store.Repository.Requests { public class MovieRequestRepository : Repository, IMovieRequestRepository { - public MovieRequestRepository(IOmbiContext ctx) : base(ctx) + public MovieRequestRepository(OmbiContext ctx) : base(ctx) { Db = ctx; } - private IOmbiContext Db { get; } + private OmbiContext Db { get; } public async Task GetRequestAsync(int theMovieDbId) { diff --git a/src/Ombi.Store/Repository/Requests/MusicRequestRepository.cs b/src/Ombi.Store/Repository/Requests/MusicRequestRepository.cs index 971d53b39..95f855ef6 100644 --- a/src/Ombi.Store/Repository/Requests/MusicRequestRepository.cs +++ b/src/Ombi.Store/Repository/Requests/MusicRequestRepository.cs @@ -11,12 +11,12 @@ namespace Ombi.Store.Repository.Requests { public class MusicRequestRepository : Repository, IMusicRequestRepository { - public MusicRequestRepository(IOmbiContext ctx) : base(ctx) + public MusicRequestRepository(OmbiContext ctx) : base(ctx) { Db = ctx; } - private IOmbiContext Db { get; } + private OmbiContext Db { get; } public Task GetRequestAsync(string foreignAlbumId) { diff --git a/src/Ombi.Store/Repository/Requests/TvRequestRepository.cs b/src/Ombi.Store/Repository/Requests/TvRequestRepository.cs index 6528f0969..823887ec4 100644 --- a/src/Ombi.Store/Repository/Requests/TvRequestRepository.cs +++ b/src/Ombi.Store/Repository/Requests/TvRequestRepository.cs @@ -8,14 +8,14 @@ using Ombi.Store.Entities.Requests; namespace Ombi.Store.Repository.Requests { - public class TvRequestRepository : BaseRepository, ITvRequestRepository + public class TvRequestRepository : BaseRepository, ITvRequestRepository { - public TvRequestRepository(IOmbiContext ctx) : base(ctx) + public TvRequestRepository(OmbiContext ctx) : base(ctx) { Db = ctx; } - public IOmbiContext Db { get; } + public OmbiContext Db { get; } public async Task GetRequestAsync(int tvDbId) { diff --git a/src/Ombi.Store/Repository/TokenRepository.cs b/src/Ombi.Store/Repository/TokenRepository.cs index 4e35b0aa8..300cc10ff 100644 --- a/src/Ombi.Store/Repository/TokenRepository.cs +++ b/src/Ombi.Store/Repository/TokenRepository.cs @@ -8,14 +8,14 @@ using Ombi.Helpers; namespace Ombi.Store.Repository { - public class TokenRepository : BaseRepository, ITokenRepository + public class TokenRepository : BaseRepository, ITokenRepository { - public TokenRepository(IOmbiContext db) : base(db) + public TokenRepository(OmbiContext db) : base(db) { Db = db; } - private IOmbiContext Db { get; } + private OmbiContext Db { get; } public async Task CreateToken(Tokens token) { diff --git a/src/Ombi.Store/Repository/UserRepository.cs b/src/Ombi.Store/Repository/UserRepository.cs index d3217aea1..c85e083ad 100644 --- a/src/Ombi.Store/Repository/UserRepository.cs +++ b/src/Ombi.Store/Repository/UserRepository.cs @@ -36,12 +36,12 @@ namespace Ombi.Store.Repository { //public class UserRepository : IUserRepository //{ - // public UserRepository(IOmbiContext ctx) + // public UserRepository(OmbiContext ctx) // { // Db = ctx; // } - // private IOmbiContext Db { get; } + // private OmbiContext Db { get; } // public async Task GetUser(string username) // { diff --git a/src/Ombi/DatabaseExtensions.cs b/src/Ombi/DatabaseExtensions.cs new file mode 100644 index 000000000..82a0084da --- /dev/null +++ b/src/Ombi/DatabaseExtensions.cs @@ -0,0 +1,26 @@ +using System.IO; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Ombi.Helpers; +using Ombi.Store.Context; + +namespace Ombi +{ + public static class DatabaseExtensions + { + public static void ConfigureDatabases(this IServiceCollection services) + { + services.AddDbContext(ConfigureSqlite); + } + + private static void ConfigureSqlite(DbContextOptionsBuilder options) + { + var i = StoragePathSingleton.Instance; + if (string.IsNullOrEmpty(i.StoragePath)) + { + i.StoragePath = string.Empty; + } + options.UseSqlite($"Data Source={Path.Combine(i.StoragePath, "Ombi.db")}"); + } + } +} \ No newline at end of file diff --git a/src/Ombi/Ombi.csproj b/src/Ombi/Ombi.csproj index 02e11c84b..a5a3ed68e 100644 --- a/src/Ombi/Ombi.csproj +++ b/src/Ombi/Ombi.csproj @@ -79,6 +79,7 @@ + diff --git a/src/Ombi/Program.cs b/src/Ombi/Program.cs index dd0baa8d4..7eecf0b8e 100644 --- a/src/Ombi/Program.cs +++ b/src/Ombi/Program.cs @@ -50,7 +50,7 @@ namespace Ombi instance.StoragePath = storagePath ?? string.Empty; // Check if we need to migrate the settings DeleteSchedules(); - CheckAndMigrate(); + //CheckAndMigrate(); var ctx = new SettingsContext(); var config = ctx.ApplicationConfigurations.ToList(); var url = config.FirstOrDefault(x => x.Type == ConfigurationTypes.Url); @@ -132,156 +132,156 @@ 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; - } - } + ///// + ///// 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) diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index c353bcf6a..8820f7721 100755 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -73,7 +73,7 @@ namespace Ombi options.User.AllowedUserNameCharacters = string.Empty; }); - + services.ConfigureDatabases(); services.AddHealthChecks(); services.AddMemoryCache(); @@ -122,7 +122,7 @@ namespace Ombi app.UseQuartz().GetAwaiter().GetResult(); - var ctx = serviceProvider.GetService(); + var ctx = serviceProvider.GetService(); loggerFactory.AddSerilog(); app.UseHealthChecks("/health");