mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Got the new DB structure in place
This commit is contained in:
parent
d13a1865ea
commit
37aca4e423
21 changed files with 235 additions and 235 deletions
|
@ -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> 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<NotificationTemplates> NotificationTemplates { get; set; }
|
||||
DbSet<ApplicationConfiguration> ApplicationConfigurations { get; set; }
|
||||
DbSet<Votes> Votes { get; set; }
|
||||
void Seed();
|
||||
DbSet<Audit> Audit { get; set; }
|
||||
DbSet<MovieRequests> MovieRequests { get; set; }
|
||||
DbSet<AlbumRequest> AlbumRequests { get; set; }
|
||||
DbSet<TvRequests> TvRequests { get; set; }
|
||||
DbSet<ChildRequests> ChildRequests { get; set; }
|
||||
DbSet<Issues> Issues { get; set; }
|
||||
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<RequestLog> RequestLogs { get; set; }
|
||||
DbSet<RecentlyAddedLog> RecentlyAddedLogs { get; set; }
|
||||
DbSet<RequestSubscription> RequestSubscription { get; set; }
|
||||
}
|
||||
}
|
|
@ -10,19 +10,28 @@ using Ombi.Store.Entities.Requests;
|
|||
|
||||
namespace Ombi.Store.Context
|
||||
{
|
||||
public sealed class OmbiContext : IdentityDbContext<OmbiUser>, IOmbiContext
|
||||
public abstract class OmbiContext : IdentityDbContext<OmbiUser>
|
||||
{
|
||||
private static bool _created;
|
||||
public OmbiContext()
|
||||
protected OmbiContext(DbContextOptions<OmbiContext> options) : base(options)
|
||||
{
|
||||
if (_created) return;
|
||||
|
||||
|
||||
_created = true;
|
||||
Database.SetCommandTimeout(60);
|
||||
Database.Migrate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
protected OmbiContext(DbContextOptions options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public DbSet<NotificationTemplates> NotificationTemplates { get; set; }
|
||||
public DbSet<ApplicationConfiguration> ApplicationConfigurations { get; set; }
|
||||
public DbSet<PlexServerContent> PlexServerContent { get; set; }
|
||||
|
@ -60,33 +69,6 @@ namespace Ombi.Store.Context
|
|||
public DbSet<UserQualityProfiles> UserQualityProfileses { get; set; }
|
||||
public DbSet<RequestQueue> 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<PlexServerContent>().HasMany(x => x.Episodes)
|
||||
.WithOne(x => x.Series)
|
||||
.HasPrincipalKey(x => x.Key)
|
||||
.HasForeignKey(x => x.GrandparentKey);
|
||||
|
||||
builder.Entity<EmbyEpisode>()
|
||||
.HasOne(p => p.Series)
|
||||
.WithMany(b => b.Episodes)
|
||||
.HasPrincipalKey(x => x.EmbyId)
|
||||
.HasForeignKey(p => p.ParentId);
|
||||
|
||||
base.OnModelCreating(builder);
|
||||
}
|
||||
|
||||
|
||||
public void Seed()
|
||||
{
|
||||
|
||||
|
|
35
src/Ombi.Store/Context/OmbiSqliteContext.cs
Normal file
35
src/Ombi.Store/Context/OmbiSqliteContext.cs
Normal file
|
@ -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<OmbiSqliteContext> options) : base(options)
|
||||
{
|
||||
if (_created) return;
|
||||
|
||||
|
||||
_created = true;
|
||||
Database.SetCommandTimeout(60);
|
||||
Database.Migrate();
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.Entity<PlexServerContent>().HasMany(x => x.Episodes)
|
||||
.WithOne(x => x.Series)
|
||||
.HasPrincipalKey(x => x.Key)
|
||||
.HasForeignKey(x => x.GrandparentKey);
|
||||
|
||||
builder.Entity<EmbyEpisode>()
|
||||
.HasOne(p => p.Series)
|
||||
.WithMany(b => b.Episodes)
|
||||
.HasPrincipalKey(x => x.EmbyId)
|
||||
.HasForeignKey(p => p.ParentId);
|
||||
|
||||
base.OnModelCreating(builder);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -13,7 +13,7 @@ using Polly;
|
|||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class BaseRepository<T, U> : IRepository<T> where T : Entity where U : IDbContext
|
||||
public class BaseRepository<T, U> : IRepository<T> where T : Entity where U : DbContext
|
||||
{
|
||||
public BaseRepository(U ctx)
|
||||
{
|
||||
|
|
|
@ -38,12 +38,12 @@ namespace Ombi.Store.Repository
|
|||
public class EmbyContentRepository : ExternalRepository<EmbyContent>, 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<EmbyContent> GetByImdbId(string imdbid)
|
||||
|
|
|
@ -3,9 +3,9 @@ using Ombi.Store.Entities;
|
|||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class ExternalRepository<T> : BaseRepository<T, IExternalContext>, IExternalRepository<T> where T : Entity
|
||||
public class ExternalRepository<T> : BaseRepository<T, ExternalContext>, IExternalRepository<T> where T : Entity
|
||||
{
|
||||
public ExternalRepository(IExternalContext ctx) : base(ctx)
|
||||
public ExternalRepository(ExternalContext ctx) : base(ctx)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<NotificationTemplates> All()
|
||||
{
|
||||
|
|
|
@ -39,12 +39,12 @@ namespace Ombi.Store.Repository
|
|||
public class PlexServerContentRepository : ExternalRepository<PlexServerContent>, 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<bool> ContentExists(string providerId)
|
||||
|
|
|
@ -3,9 +3,9 @@ using Ombi.Store.Entities;
|
|||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class Repository<T> : BaseRepository<T,IOmbiContext>, IRepository<T> where T : Entity
|
||||
public class Repository<T> : BaseRepository<T, OmbiContext>, IRepository<T> where T : Entity
|
||||
{
|
||||
public Repository(IOmbiContext ctx) : base(ctx)
|
||||
public Repository(OmbiContext ctx) : base(ctx)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace Ombi.Store.Repository.Requests
|
|||
{
|
||||
public interface ITvRequestRepository
|
||||
{
|
||||
IOmbiContext Db { get; }
|
||||
OmbiContext Db { get; }
|
||||
Task<TvRequests> Add(TvRequests request);
|
||||
Task<ChildRequests> AddChild(ChildRequests request);
|
||||
Task Delete(TvRequests request);
|
||||
|
|
|
@ -11,12 +11,12 @@ namespace Ombi.Store.Repository.Requests
|
|||
{
|
||||
public class MovieRequestRepository : Repository<MovieRequests>, 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<MovieRequests> GetRequestAsync(int theMovieDbId)
|
||||
{
|
||||
|
|
|
@ -11,12 +11,12 @@ namespace Ombi.Store.Repository.Requests
|
|||
{
|
||||
public class MusicRequestRepository : Repository<AlbumRequest>, 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<AlbumRequest> GetRequestAsync(string foreignAlbumId)
|
||||
{
|
||||
|
|
|
@ -8,14 +8,14 @@ using Ombi.Store.Entities.Requests;
|
|||
|
||||
namespace Ombi.Store.Repository.Requests
|
||||
{
|
||||
public class TvRequestRepository : BaseRepository<TvRequests, IOmbiContext>, ITvRequestRepository
|
||||
public class TvRequestRepository : BaseRepository<TvRequests, OmbiContext>, 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<TvRequests> GetRequestAsync(int tvDbId)
|
||||
{
|
||||
|
|
|
@ -8,14 +8,14 @@ using Ombi.Helpers;
|
|||
|
||||
namespace Ombi.Store.Repository
|
||||
{
|
||||
public class TokenRepository : BaseRepository<Tokens, IOmbiContext>, ITokenRepository
|
||||
public class TokenRepository : BaseRepository<Tokens, OmbiContext>, 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)
|
||||
{
|
||||
|
|
|
@ -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<User> GetUser(string username)
|
||||
// {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue