mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 08:16:05 -07:00
Done the migration for the external db !wip
This commit is contained in:
parent
26da9d242c
commit
ca48361865
15 changed files with 112 additions and 53 deletions
|
@ -7,12 +7,12 @@ namespace Ombi.Core.Rule.Rules.Request
|
|||
{
|
||||
public class SonarrCacheRequestRule : BaseRequestRule, IRules<BaseRequest>
|
||||
{
|
||||
public SonarrCacheRequestRule(IOmbiContext ctx)
|
||||
public SonarrCacheRequestRule(IExternalContext ctx)
|
||||
{
|
||||
_ctx = ctx;
|
||||
}
|
||||
|
||||
private readonly IOmbiContext _ctx;
|
||||
private readonly IExternalContext _ctx;
|
||||
|
||||
public Task<RuleResult> Execute(BaseRequest obj)
|
||||
{
|
||||
|
|
|
@ -34,12 +34,12 @@ namespace Ombi.Core.Rule.Rules.Search
|
|||
{
|
||||
public class SonarrCacheSearchRule : BaseSearchRule, IRules<SearchViewModel>
|
||||
{
|
||||
public SonarrCacheSearchRule(IOmbiContext ctx)
|
||||
public SonarrCacheSearchRule(IExternalContext ctx)
|
||||
{
|
||||
_ctx = ctx;
|
||||
}
|
||||
|
||||
private readonly IOmbiContext _ctx;
|
||||
private readonly IExternalContext _ctx;
|
||||
|
||||
public Task<RuleResult> Execute(SearchViewModel obj)
|
||||
{
|
||||
|
|
|
@ -10,12 +10,12 @@ namespace Ombi.Core.Rule.Rules
|
|||
{
|
||||
public class SonarrCacheRule
|
||||
{
|
||||
public SonarrCacheRule(IOmbiContext ctx)
|
||||
public SonarrCacheRule(IExternalContext ctx)
|
||||
{
|
||||
_ctx = ctx;
|
||||
}
|
||||
|
||||
private readonly IOmbiContext _ctx;
|
||||
private readonly IExternalContext _ctx;
|
||||
|
||||
public async Task<RuleResult> Execute(BaseRequest obj)
|
||||
{
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace Ombi.Schedule.Jobs.Couchpotato
|
|||
public class CouchPotatoSync : ICouchPotatoSync
|
||||
{
|
||||
public CouchPotatoSync(ISettingsService<CouchPotatoSettings> cpSettings,
|
||||
ICouchPotatoApi api, ILogger<CouchPotatoSync> log, IOmbiContext ctx)
|
||||
ICouchPotatoApi api, ILogger<CouchPotatoSync> log, IExternalContext ctx)
|
||||
{
|
||||
_settings = cpSettings;
|
||||
_api = api;
|
||||
|
@ -54,7 +54,7 @@ namespace Ombi.Schedule.Jobs.Couchpotato
|
|||
private readonly ISettingsService<CouchPotatoSettings> _settings;
|
||||
private readonly ICouchPotatoApi _api;
|
||||
private readonly ILogger<CouchPotatoSync> _log;
|
||||
private readonly IOmbiContext _ctx;
|
||||
private readonly IExternalContext _ctx;
|
||||
|
||||
public async Task Start()
|
||||
{
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Ombi.Schedule.Jobs.Lidarr
|
|||
{
|
||||
public class LidarrAlbumSync : ILidarrAlbumSync
|
||||
{
|
||||
public LidarrAlbumSync(ISettingsService<LidarrSettings> lidarr, ILidarrApi lidarrApi, ILogger<LidarrAlbumSync> log, IOmbiContext ctx,
|
||||
public LidarrAlbumSync(ISettingsService<LidarrSettings> lidarr, ILidarrApi lidarrApi, ILogger<LidarrAlbumSync> log, IExternalContext ctx,
|
||||
IBackgroundJobClient job, ILidarrAvailabilityChecker availability)
|
||||
{
|
||||
_lidarrSettings = lidarr;
|
||||
|
@ -35,7 +35,7 @@ namespace Ombi.Schedule.Jobs.Lidarr
|
|||
private readonly ISettingsService<LidarrSettings> _lidarrSettings;
|
||||
private readonly ILidarrApi _lidarrApi;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOmbiContext _ctx;
|
||||
private readonly IExternalContext _ctx;
|
||||
private readonly IBackgroundJobClient _job;
|
||||
private readonly ILidarrAvailabilityChecker _availability;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace Ombi.Schedule.Jobs.Lidarr
|
|||
{
|
||||
public class LidarrArtistSync : ILidarrArtistSync
|
||||
{
|
||||
public LidarrArtistSync(ISettingsService<LidarrSettings> lidarr, ILidarrApi lidarrApi, ILogger<LidarrArtistSync> log, IOmbiContext ctx,
|
||||
public LidarrArtistSync(ISettingsService<LidarrSettings> lidarr, ILidarrApi lidarrApi, ILogger<LidarrArtistSync> log, IExternalContext ctx,
|
||||
IBackgroundJobClient background, ILidarrAlbumSync album)
|
||||
{
|
||||
_lidarrSettings = lidarr;
|
||||
|
@ -35,7 +35,7 @@ namespace Ombi.Schedule.Jobs.Lidarr
|
|||
private readonly ISettingsService<LidarrSettings> _lidarrSettings;
|
||||
private readonly ILidarrApi _lidarrApi;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOmbiContext _ctx;
|
||||
private readonly IExternalContext _ctx;
|
||||
private readonly IBackgroundJobClient _job;
|
||||
private readonly ILidarrAlbumSync _albumSync;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|||
{
|
||||
public class RadarrSync : IRadarrSync
|
||||
{
|
||||
public RadarrSync(ISettingsService<RadarrSettings> radarr, IRadarrApi radarrApi, ILogger<RadarrSync> log, IOmbiContext ctx)
|
||||
public RadarrSync(ISettingsService<RadarrSettings> radarr, IRadarrApi radarrApi, ILogger<RadarrSync> log, IExternalContext ctx)
|
||||
{
|
||||
RadarrSettings = radarr;
|
||||
RadarrApi = radarrApi;
|
||||
|
@ -28,7 +28,7 @@ namespace Ombi.Schedule.Jobs.Radarr
|
|||
private ISettingsService<RadarrSettings> RadarrSettings { get; }
|
||||
private IRadarrApi RadarrApi { get; }
|
||||
private ILogger<RadarrSync> Logger { get; }
|
||||
private readonly IOmbiContext _ctx;
|
||||
private readonly IExternalContext _ctx;
|
||||
|
||||
private static readonly SemaphoreSlim SemaphoreSlim = new SemaphoreSlim(1, 1);
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@ -17,7 +16,7 @@ namespace Ombi.Schedule.Jobs.SickRage
|
|||
{
|
||||
public class SickRageSync : ISickRageSync
|
||||
{
|
||||
public SickRageSync(ISettingsService<SickRageSettings> s, ISickRageApi api, ILogger<SickRageSync> l, IOmbiContext ctx)
|
||||
public SickRageSync(ISettingsService<SickRageSettings> s, ISickRageApi api, ILogger<SickRageSync> l, IExternalContext ctx)
|
||||
{
|
||||
_settings = s;
|
||||
_api = api;
|
||||
|
@ -29,7 +28,7 @@ namespace Ombi.Schedule.Jobs.SickRage
|
|||
private readonly ISettingsService<SickRageSettings> _settings;
|
||||
private readonly ISickRageApi _api;
|
||||
private readonly ILogger<SickRageSync> _log;
|
||||
private readonly IOmbiContext _ctx;
|
||||
private readonly IExternalContext _ctx;
|
||||
|
||||
public async Task Start()
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Ombi.Schedule.Jobs.Sonarr
|
|||
{
|
||||
public class SonarrSync : ISonarrSync
|
||||
{
|
||||
public SonarrSync(ISettingsService<SonarrSettings> s, ISonarrApi api, ILogger<SonarrSync> l, IOmbiContext ctx)
|
||||
public SonarrSync(ISettingsService<SonarrSettings> s, ISonarrApi api, ILogger<SonarrSync> l, IExternalContext ctx)
|
||||
{
|
||||
_settings = s;
|
||||
_api = api;
|
||||
|
@ -31,7 +31,7 @@ namespace Ombi.Schedule.Jobs.Sonarr
|
|||
private readonly ISettingsService<SonarrSettings> _settings;
|
||||
private readonly ISonarrApi _api;
|
||||
private readonly ILogger<SonarrSync> _log;
|
||||
private readonly IOmbiContext _ctx;
|
||||
private readonly IExternalContext _ctx;
|
||||
|
||||
public async Task Start()
|
||||
{
|
||||
|
|
|
@ -12,12 +12,12 @@ namespace Ombi.Store.Context
|
|||
public interface IOmbiContext : IDbContext
|
||||
{
|
||||
|
||||
DbSet<PlexServerContent> PlexServerContent { get; set; }
|
||||
DbSet<PlexEpisode> PlexEpisode { get; set; }
|
||||
//DbSet<PlexServerContent> PlexServerContent { get; set; }
|
||||
//DbSet<PlexEpisode> PlexEpisode { get; set; }
|
||||
DbSet<GlobalSettings> Settings { get; set; }
|
||||
DbSet<RadarrCache> RadarrCache { get; set; }
|
||||
DbSet<EmbyContent> EmbyContent { get; set; }
|
||||
DbSet<EmbyEpisode> EmbyEpisode { get; set; }
|
||||
//DbSet<RadarrCache> RadarrCache { get; set; }
|
||||
//DbSet<EmbyContent> EmbyContent { get; set; }
|
||||
//DbSet<EmbyEpisode> EmbyEpisode { get; set; }
|
||||
DbSet<NotificationTemplates> NotificationTemplates { get; set; }
|
||||
DbSet<ApplicationConfiguration> ApplicationConfigurations { get; set; }
|
||||
DbSet<Audit> Audit { get; set; }
|
||||
|
@ -29,12 +29,12 @@ namespace Ombi.Store.Context
|
|||
DbSet<IssueCategory> IssueCategories { get; set; }
|
||||
DbSet<Tokens> Tokens { get; set; }
|
||||
DbSet<SonarrCache> SonarrCache { get; set; }
|
||||
DbSet<SonarrEpisodeCache> SonarrEpisodeCache { get; set; }
|
||||
DbSet<CouchPotatoCache> CouchPotatoCache { get; set; }
|
||||
DbSet<SickRageCache> SickRageCache { get; set; }
|
||||
DbSet<LidarrArtistCache> LidarrArtistCache { get; set; }
|
||||
DbSet<LidarrAlbumCache> LidarrAlbumCache { get; set; }
|
||||
DbSet<SickRageEpisodeCache> SickRageEpisodeCache { get; set; }
|
||||
//DbSet<SonarrEpisodeCache> SonarrEpisodeCache { get; set; }
|
||||
//DbSet<CouchPotatoCache> CouchPotatoCache { get; set; }
|
||||
//DbSet<SickRageCache> SickRageCache { get; set; }
|
||||
//DbSet<LidarrArtistCache> LidarrArtistCache { get; set; }
|
||||
//DbSet<LidarrAlbumCache> LidarrAlbumCache { get; set; }
|
||||
//DbSet<SickRageEpisodeCache> SickRageEpisodeCache { get; set; }
|
||||
DbSet<RequestLog> RequestLogs { get; set; }
|
||||
DbSet<RecentlyAddedLog> RecentlyAddedLogs { get; set; }
|
||||
DbSet<RequestSubscription> RequestSubscription { get; set; }
|
||||
|
|
|
@ -42,11 +42,6 @@ namespace Ombi.Store.Entities
|
|||
public PlexMediaTypeEntity Type { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only used for TV Shows
|
||||
/// </summary>
|
||||
public virtual ICollection<PlexSeasonsContent> Seasons { get; set; }
|
||||
|
||||
public ICollection<PlexEpisode> Episodes { get; set; }
|
||||
|
||||
|
@ -67,15 +62,6 @@ namespace Ombi.Store.Entities
|
|||
public bool HasTheMovieDb => !string.IsNullOrEmpty(TheMovieDbId);
|
||||
}
|
||||
|
||||
[Table("PlexSeasonsContent")]
|
||||
public class PlexSeasonsContent : Entity
|
||||
{
|
||||
public int PlexContentId { get; set; }
|
||||
public int SeasonNumber { get; set; }
|
||||
public int SeasonKey { get; set; }
|
||||
public int ParentKey { get; set; }
|
||||
}
|
||||
|
||||
public enum PlexMediaTypeEntity
|
||||
{
|
||||
Movie = 0,
|
||||
|
|
|
@ -35,15 +35,15 @@ using Ombi.Store.Entities;
|
|||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class EmbyContentRepository : Repository<EmbyContent>, IEmbyContentRepository
|
||||
public class EmbyContentRepository : ExternalRepository<EmbyContent>, IEmbyContentRepository
|
||||
{
|
||||
|
||||
public EmbyContentRepository(IOmbiContext db):base(db)
|
||||
public EmbyContentRepository(IExternalContext db):base(db)
|
||||
{
|
||||
Db = db;
|
||||
}
|
||||
|
||||
private IOmbiContext Db { get; }
|
||||
private IExternalContext Db { get; }
|
||||
|
||||
|
||||
public async Task<EmbyContent> GetByImdbId(string imdbid)
|
||||
|
|
|
@ -7,7 +7,7 @@ using Ombi.Store.Entities;
|
|||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public interface IPlexContentRepository : IRepository<PlexServerContent>
|
||||
public interface IPlexContentRepository : IExternalRepository<PlexServerContent>
|
||||
{
|
||||
Task<bool> ContentExists(string providerId);
|
||||
Task<PlexServerContent> Get(string providerId);
|
||||
|
|
|
@ -36,15 +36,15 @@ using Ombi.Store.Entities;
|
|||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class PlexServerContentRepository : Repository<PlexServerContent>, IPlexContentRepository
|
||||
public class PlexServerContentRepository : ExternalRepository<PlexServerContent>, IPlexContentRepository
|
||||
{
|
||||
|
||||
public PlexServerContentRepository(IOmbiContext db) : base(db)
|
||||
public PlexServerContentRepository(IExternalContext db) : base(db)
|
||||
{
|
||||
Db = db;
|
||||
}
|
||||
|
||||
private IOmbiContext Db { get; }
|
||||
private IExternalContext Db { get; }
|
||||
|
||||
|
||||
public async Task<bool> ContentExists(string providerId)
|
||||
|
|
|
@ -143,13 +143,87 @@ namespace Ombi
|
|||
}
|
||||
|
||||
// Now delete the old stuff
|
||||
if(doneGlobal)
|
||||
if (doneGlobal)
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE GlobalSettings");
|
||||
if(doneConfig)
|
||||
if (doneConfig)
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE ApplicationConfiguration");
|
||||
|
||||
}
|
||||
|
||||
// Now migrate all the external stuff
|
||||
using (var ombi = new OmbiContext())
|
||||
using (var external = new ExternalContext())
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (ombi.PlexEpisode.Any())
|
||||
{
|
||||
external.PlexEpisode.AddRange(ombi.PlexEpisode.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE PlexEpisode");
|
||||
}
|
||||
|
||||
if (ombi.PlexServerContent.Any())
|
||||
{
|
||||
external.PlexServerContent.AddRange(ombi.PlexServerContent.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE PlexServerContent");
|
||||
}
|
||||
if (ombi.EmbyEpisode.Any())
|
||||
{
|
||||
external.EmbyEpisode.AddRange(ombi.EmbyEpisode.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE EmbyEpisode");
|
||||
}
|
||||
|
||||
if (ombi.EmbyContent.Any())
|
||||
{
|
||||
external.EmbyContent.AddRange(ombi.EmbyContent.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE EmbyContent");
|
||||
}
|
||||
if (ombi.RadarrCache.Any())
|
||||
{
|
||||
external.RadarrCache.AddRange(ombi.RadarrCache.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE RadarrCache");
|
||||
}
|
||||
if (ombi.SonarrCache.Any())
|
||||
{
|
||||
external.SonarrCache.AddRange(ombi.SonarrCache.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE SonarrCache");
|
||||
}
|
||||
if (ombi.LidarrAlbumCache.Any())
|
||||
{
|
||||
external.LidarrAlbumCache.AddRange(ombi.LidarrAlbumCache.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE LidarrAlbumCache");
|
||||
}
|
||||
if (ombi.LidarrArtistCache.Any())
|
||||
{
|
||||
external.LidarrArtistCache.AddRange(ombi.LidarrArtistCache.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE LidarrArtistCache");
|
||||
}
|
||||
if (ombi.SickRageEpisodeCache.Any())
|
||||
{
|
||||
external.SickRageEpisodeCache.AddRange(ombi.SickRageEpisodeCache.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE SickRageEpisodeCache");
|
||||
}
|
||||
if (ombi.SickRageCache.Any())
|
||||
{
|
||||
external.SickRageCache.AddRange(ombi.SickRageCache.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE SickRageCache");
|
||||
}
|
||||
if (ombi.CouchPotatoCache.Any())
|
||||
{
|
||||
external.CouchPotatoCache.AddRange(ombi.CouchPotatoCache.ToList());
|
||||
ombi.Database.ExecuteSqlCommand("TRUNCATE TABLE CouchPotatoCache");
|
||||
}
|
||||
|
||||
external.SaveChanges();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void DeleteSchedulesDb()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue