mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 18:47:15 -07:00
Added a DBSchema so we have an easier way to update the DB
This commit is contained in:
parent
2ad36fa20f
commit
425302ba12
7 changed files with 116 additions and 4 deletions
|
@ -46,6 +46,10 @@
|
|||
<HintPath>..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.2.3\lib\net45\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Octokit, Version=0.19.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Octokit.0.19.0\lib\net45\Octokit.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
|
|
|
@ -30,6 +30,7 @@ using System.Collections.Generic;
|
|||
using System.Linq;
|
||||
|
||||
using Mono.Data.Sqlite;
|
||||
using NLog;
|
||||
using PlexRequests.Api;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
|
@ -40,6 +41,9 @@ namespace PlexRequests.Core
|
|||
{
|
||||
public class Setup
|
||||
{
|
||||
public const int SchemaVersion = 1;
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
private static DbConfiguration Db { get; set; }
|
||||
public string SetupDb()
|
||||
{
|
||||
|
@ -53,11 +57,40 @@ namespace PlexRequests.Core
|
|||
}
|
||||
|
||||
MigrateDb();
|
||||
CheckSchema();
|
||||
return Db.DbConnection().ConnectionString;
|
||||
}
|
||||
|
||||
public static string ConnectionString => Db.DbConnection().ConnectionString;
|
||||
|
||||
|
||||
private void CheckSchema()
|
||||
{
|
||||
var connection = Db.DbConnection();
|
||||
var schema = connection.GetSchemaVersion();
|
||||
if (schema == null)
|
||||
{
|
||||
connection.CreateSchema(); // Set the default.
|
||||
schema = connection.GetSchemaVersion();
|
||||
}
|
||||
|
||||
var version = schema.SchemaVersion;
|
||||
if (version == 0)
|
||||
{
|
||||
connection.UpdateSchemaVersion(SchemaVersion);
|
||||
try
|
||||
{
|
||||
TableCreation.AlterTable(Db.DbConnection(), "RequestBlobs", "ADD COLUMN", "MusicId", false, "INTEGER");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error("Tried updating the schema to version 1");
|
||||
Log.Error(e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateDefaultSettingsPage()
|
||||
{
|
||||
var defaultSettings = new PlexRequestSettings
|
||||
|
@ -74,6 +107,7 @@ namespace PlexRequests.Core
|
|||
|
||||
private void MigrateDb() // TODO: Remove in v1.7
|
||||
{
|
||||
|
||||
var result = new List<long>();
|
||||
RequestedModel[] requestedModels;
|
||||
var repo = new GenericRepository<RequestedModel>(Db, new MemoryCacheProvider());
|
||||
|
@ -121,7 +155,7 @@ namespace PlexRequests.Core
|
|||
result.Add(id);
|
||||
}
|
||||
|
||||
foreach (var source in requestedModels.Where(x => x.Type== RequestType.Movie))
|
||||
foreach (var source in requestedModels.Where(x => x.Type == RequestType.Movie))
|
||||
{
|
||||
var id = jsonRepo.AddRequest(source);
|
||||
result.Add(id);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<package id="Nancy" version="1.4.3" targetFramework="net452" />
|
||||
<package id="Nancy.Authentication.Forms" version="1.4.1" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net452" />
|
||||
<package id="NLog" version="4.2.3" targetFramework="net46" />
|
||||
<package id="Octokit" version="0.19.0" targetFramework="net46" />
|
||||
<package id="valueinjecter" version="3.1.1.2" targetFramework="net452" />
|
||||
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue