mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
The settings have now been split out of the main db.
Next is the External stuff e.g. Plex/Emby/Sonarr/Radarr stuff
This commit is contained in:
parent
66af499970
commit
618ee16d9d
17 changed files with 328 additions and 69 deletions
22
src/Ombi.Store/Context/IDbContext.cs
Normal file
22
src/Ombi.Store/Context/IDbContext.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
|
||||
namespace Ombi.Store.Context
|
||||
{
|
||||
public interface IDbContext : IDisposable
|
||||
{
|
||||
EntityEntry Update(object entity);
|
||||
EntityEntry<TEntity> Update<TEntity>(TEntity entity) where TEntity : class;
|
||||
int SaveChanges();
|
||||
void Seed();
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
|
||||
DatabaseFacade Database { get; }
|
||||
EntityEntry<T> Entry<T>(T entry) where T : class;
|
||||
EntityEntry<TEntity> Attach<TEntity>(TEntity entity) where TEntity : class;
|
||||
DbSet<TEntity> Set<TEntity>() where TEntity : class;
|
||||
}
|
||||
}
|
|
@ -9,23 +9,17 @@ using Ombi.Store.Entities.Requests;
|
|||
|
||||
namespace Ombi.Store.Context
|
||||
{
|
||||
public interface IOmbiContext : IDisposable
|
||||
public interface IOmbiContext : IDbContext
|
||||
{
|
||||
int SaveChanges();
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
|
||||
DbSet<GlobalSettings> Settings { 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; }
|
||||
DatabaseFacade Database { get; }
|
||||
EntityEntry<T> Entry<T>(T entry) where T : class;
|
||||
EntityEntry<TEntity> Attach<TEntity>(TEntity entity) where TEntity : class;
|
||||
DbSet<TEntity> Set<TEntity>() where TEntity : class;
|
||||
DbSet<NotificationTemplates> NotificationTemplates { get; set; }
|
||||
DbSet<ApplicationConfiguration> ApplicationConfigurations { get; set; }
|
||||
void Seed();
|
||||
DbSet<Audit> Audit { get; set; }
|
||||
DbSet<MovieRequests> MovieRequests { get; set; }
|
||||
DbSet<AlbumRequest> AlbumRequests { get; set; }
|
||||
|
@ -36,8 +30,6 @@ namespace Ombi.Store.Context
|
|||
DbSet<Tokens> Tokens { get; set; }
|
||||
DbSet<SonarrCache> SonarrCache { get; set; }
|
||||
DbSet<SonarrEpisodeCache> SonarrEpisodeCache { get; set; }
|
||||
EntityEntry Update(object entity);
|
||||
EntityEntry<TEntity> Update<TEntity>(TEntity entity) where TEntity : class;
|
||||
DbSet<CouchPotatoCache> CouchPotatoCache { get; set; }
|
||||
DbSet<SickRageCache> SickRageCache { get; set; }
|
||||
DbSet<LidarrArtistCache> LidarrArtistCache { get; set; }
|
||||
|
|
11
src/Ombi.Store/Context/ISettingsContext.cs
Normal file
11
src/Ombi.Store/Context/ISettingsContext.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Context
|
||||
{
|
||||
public interface ISettingsContext : IDbContext
|
||||
{
|
||||
DbSet<ApplicationConfiguration> ApplicationConfigurations { get; set; }
|
||||
DbSet<GlobalSettings> Settings { get; set; }
|
||||
}
|
||||
}
|
|
@ -22,9 +22,10 @@ namespace Ombi.Store.Context
|
|||
}
|
||||
|
||||
public DbSet<NotificationTemplates> NotificationTemplates { get; set; }
|
||||
public DbSet<GlobalSettings> Settings { get; set; }
|
||||
public DbSet<ApplicationConfiguration> ApplicationConfigurations { get; set; }
|
||||
public DbSet<PlexServerContent> PlexServerContent { get; set; }
|
||||
public DbSet<PlexEpisode> PlexEpisode { get; set; }
|
||||
public DbSet<GlobalSettings> Settings { get; set; }
|
||||
public DbSet<RadarrCache> RadarrCache { get; set; }
|
||||
public DbSet<CouchPotatoCache> CouchPotatoCache { get; set; }
|
||||
public DbSet<EmbyContent> EmbyContent { get; set; }
|
||||
|
@ -53,7 +54,6 @@ namespace Ombi.Store.Context
|
|||
public DbSet<RequestSubscription> RequestSubscription { get; set; }
|
||||
public DbSet<UserNotificationPreferences> UserNotificationPreferences { get; set; }
|
||||
public DbSet<UserQualityProfiles> UserQualityProfileses { get; set; }
|
||||
public DbSet<ApplicationConfiguration> ApplicationConfigurations { get; set; }
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
|
@ -84,39 +84,6 @@ namespace Ombi.Store.Context
|
|||
|
||||
public void Seed()
|
||||
{
|
||||
|
||||
// Add the tokens
|
||||
var fanArt = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);
|
||||
if (fanArt == null)
|
||||
{
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
{
|
||||
Type = ConfigurationTypes.FanartTv,
|
||||
Value = "4b6d983efa54d8f45c68432521335f15"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
var movieDb = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);
|
||||
if (movieDb == null)
|
||||
{
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
{
|
||||
Type = ConfigurationTypes.TheMovieDb,
|
||||
Value = "b8eabaf5608b88d0298aa189dd90bf00"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
var notification = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.Notification);
|
||||
if (notification == null)
|
||||
{
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
{
|
||||
Type = ConfigurationTypes.Notification,
|
||||
Value = "4f0260c4-9c3d-41ab-8d68-27cb5a593f0e"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
// VACUUM;
|
||||
Database.ExecuteSqlCommand("VACUUM;");
|
||||
|
||||
|
|
70
src/Ombi.Store/Context/SettingsContext.cs
Normal file
70
src/Ombi.Store/Context/SettingsContext.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Entities;
|
||||
|
||||
namespace Ombi.Store.Context
|
||||
{
|
||||
public sealed class SettingsContext : DbContext, ISettingsContext
|
||||
{
|
||||
private static bool _created;
|
||||
public SettingsContext()
|
||||
{
|
||||
if (_created) return;
|
||||
|
||||
_created = true;
|
||||
Database.Migrate();
|
||||
}
|
||||
|
||||
public DbSet<GlobalSettings> Settings { get; set; }
|
||||
public DbSet<ApplicationConfiguration> 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()
|
||||
{
|
||||
// Add the tokens
|
||||
var fanArt = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);
|
||||
if (fanArt == null)
|
||||
{
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
{
|
||||
Type = ConfigurationTypes.FanartTv,
|
||||
Value = "4b6d983efa54d8f45c68432521335f15"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
var movieDb = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.FanartTv);
|
||||
if (movieDb == null)
|
||||
{
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
{
|
||||
Type = ConfigurationTypes.TheMovieDb,
|
||||
Value = "b8eabaf5608b88d0298aa189dd90bf00"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
var notification = ApplicationConfigurations.FirstOrDefault(x => x.Type == ConfigurationTypes.Notification);
|
||||
if (notification == null)
|
||||
{
|
||||
ApplicationConfigurations.Add(new ApplicationConfiguration
|
||||
{
|
||||
Type = ConfigurationTypes.Notification,
|
||||
Value = "4f0260c4-9c3d-41ab-8d68-27cb5a593f0e"
|
||||
});
|
||||
SaveChanges();
|
||||
}
|
||||
|
||||
SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
50
src/Ombi.Store/Migrations/Settings/20181004132516_Inital.Designer.cs
generated
Normal file
50
src/Ombi.Store/Migrations/Settings/20181004132516_Inital.Designer.cs
generated
Normal file
|
@ -0,0 +1,50 @@
|
|||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Ombi.Store.Context;
|
||||
|
||||
namespace Ombi.Store.Migrations.Settings
|
||||
{
|
||||
[DbContext(typeof(SettingsContext))]
|
||||
[Migration("20181004132516_Inital")]
|
||||
partial class Inital
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "2.1.3-rtm-32065");
|
||||
|
||||
modelBuilder.Entity("Ombi.Store.Entities.ApplicationConfiguration", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("Type");
|
||||
|
||||
b.Property<string>("Value");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("ApplicationConfiguration");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Content");
|
||||
|
||||
b.Property<string>("SettingsName");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("GlobalSettings");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
47
src/Ombi.Store/Migrations/Settings/20181004132516_Inital.cs
Normal file
47
src/Ombi.Store/Migrations/Settings/20181004132516_Inital.cs
Normal file
|
@ -0,0 +1,47 @@
|
|||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace Ombi.Store.Migrations.Settings
|
||||
{
|
||||
public partial class Inital : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ApplicationConfiguration",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Type = table.Column<int>(nullable: false),
|
||||
Value = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ApplicationConfiguration", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "GlobalSettings",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Content = table.Column<string>(nullable: true),
|
||||
SettingsName = table.Column<string>(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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
// <auto-generated />
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Ombi.Store.Context;
|
||||
|
||||
namespace Ombi.Store.Migrations.Settings
|
||||
{
|
||||
[DbContext(typeof(SettingsContext))]
|
||||
partial class SettingsContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "2.1.3-rtm-32065");
|
||||
|
||||
modelBuilder.Entity("Ombi.Store.Entities.ApplicationConfiguration", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int>("Type");
|
||||
|
||||
b.Property<string>("Value");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("ApplicationConfiguration");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Ombi.Store.Entities.GlobalSettings", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Content");
|
||||
|
||||
b.Property<string>("SettingsName");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("GlobalSettings");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,16 +8,20 @@ namespace Ombi.Store.Repository
|
|||
{
|
||||
public class ApplicationConfigRepository : IApplicationConfigRepository
|
||||
{
|
||||
public ApplicationConfigRepository(IOmbiContext ctx)
|
||||
public ApplicationConfigRepository(ISettingsContext ctx)
|
||||
{
|
||||
Ctx = ctx;
|
||||
}
|
||||
|
||||
private IOmbiContext Ctx { get; }
|
||||
private ISettingsContext Ctx { get; }
|
||||
|
||||
public async Task<ApplicationConfiguration> Get(ConfigurationTypes type)
|
||||
public Task<ApplicationConfiguration> GetAsync(ConfigurationTypes type)
|
||||
{
|
||||
return await Ctx.ApplicationConfigurations.FirstOrDefaultAsync(x => x.Type == type);
|
||||
return Ctx.ApplicationConfigurations.FirstOrDefaultAsync(x => x.Type == type);
|
||||
}
|
||||
public ApplicationConfiguration Get(ConfigurationTypes type)
|
||||
{
|
||||
return Ctx.ApplicationConfigurations.FirstOrDefault(x => x.Type == type);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ namespace Ombi.Store.Repository
|
|||
{
|
||||
public interface IApplicationConfigRepository
|
||||
{
|
||||
Task<ApplicationConfiguration> Get(ConfigurationTypes type);
|
||||
Task<ApplicationConfiguration> GetAsync(ConfigurationTypes type);
|
||||
ApplicationConfiguration Get(ConfigurationTypes type);
|
||||
}
|
||||
}
|
|
@ -12,13 +12,13 @@ namespace Ombi.Store.Repository
|
|||
{
|
||||
public class SettingsJsonRepository : ISettingsRepository
|
||||
{
|
||||
public SettingsJsonRepository(IOmbiContext ctx, ICacheService mem)
|
||||
public SettingsJsonRepository(ISettingsContext ctx, ICacheService mem)
|
||||
{
|
||||
Db = ctx;
|
||||
_cache = mem;
|
||||
}
|
||||
|
||||
private IOmbiContext Db { get; }
|
||||
private ISettingsContext Db { get; }
|
||||
private readonly ICacheService _cache;
|
||||
|
||||
public GlobalSettings Insert(GlobalSettings entity)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue