mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 19:40:05 -07:00
Added migration code and cleaned up the DB
This commit is contained in:
parent
ce416ae046
commit
b62b7c1305
8 changed files with 34 additions and 76 deletions
|
@ -32,7 +32,7 @@ namespace PlexRequests.Core
|
|||
{
|
||||
public interface IRequestService
|
||||
{
|
||||
long AddRequest(int providerId, RequestedModel model);
|
||||
long AddRequest(RequestedModel model);
|
||||
bool CheckRequest(int providerId);
|
||||
void DeleteRequest(RequestedModel request);
|
||||
bool UpdateRequest(RequestedModel model);
|
||||
|
|
|
@ -42,7 +42,7 @@ namespace PlexRequests.Core
|
|||
Repo = repo;
|
||||
}
|
||||
private IRequestRepository Repo { get; }
|
||||
public long AddRequest(int providerId, RequestedModel model)
|
||||
public long AddRequest(RequestedModel model)
|
||||
{
|
||||
var entity = new RequestBlobs { Type = model.Type, Content = ReturnBytes(model), ProviderId = model.ProviderId };
|
||||
var id = Repo.Insert(entity);
|
||||
|
|
|
@ -40,7 +40,7 @@ namespace PlexRequests.Core
|
|||
|
||||
private IRepository<RequestedModel> Repo { get; set; }
|
||||
|
||||
public long AddRequest(int providerId, RequestedModel model)
|
||||
public long AddRequest(RequestedModel model)
|
||||
{
|
||||
return Repo.Insert(model);
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Mono.Data.Sqlite;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
using PlexRequests.Helpers;
|
||||
|
@ -46,6 +49,7 @@ namespace PlexRequests.Core
|
|||
CreateDefaultSettingsPage();
|
||||
}
|
||||
|
||||
MigrateDb();
|
||||
return Db.DbConnection().ConnectionString;
|
||||
}
|
||||
|
||||
|
@ -63,5 +67,28 @@ namespace PlexRequests.Core
|
|||
var s = new SettingsServiceV2<PlexRequestSettings>(new SettingsJsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
|
||||
s.SaveSettings(defaultSettings);
|
||||
}
|
||||
|
||||
private void MigrateDb()
|
||||
{
|
||||
var repo = new GenericRepository<RequestedModel>(Db);
|
||||
var records = repo.GetAll();
|
||||
var requestedModels = records as RequestedModel[] ?? records.ToArray();
|
||||
if(!requestedModels.Any())
|
||||
{ return; }
|
||||
|
||||
var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider()));
|
||||
var result = new List<long>();
|
||||
foreach (var r in requestedModels)
|
||||
{
|
||||
var id = jsonRepo.AddRequest(r);
|
||||
result.Add(id);
|
||||
}
|
||||
|
||||
if (result.Any(x => x == -1))
|
||||
{
|
||||
throw new SqliteException("Could not migrate the DB!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue