Catch the missing table exception when they have a new DB

pull/42/head
Jamie Rees 9 years ago
parent 2786d13a17
commit 3c6338cadc

@ -24,6 +24,8 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/ // ************************************************************************/
#endregion #endregion
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -70,18 +72,29 @@ namespace PlexRequests.Core
private void MigrateDb() // TODO: Remove when no longer needed private void MigrateDb() // TODO: Remove when no longer needed
{ {
var result = new List<long>();
RequestedModel[] requestedModels;
var repo = new GenericRepository<RequestedModel>(Db); var repo = new GenericRepository<RequestedModel>(Db);
var records = repo.GetAll(); try
var requestedModels = records as RequestedModel[] ?? records.ToArray(); {
if(!requestedModels.Any()) var records = repo.GetAll();
{ return; }
var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider())); requestedModels = records as RequestedModel[] ?? records.ToArray();
var result = new List<long>(); if (!requestedModels.Any())
foreach (var r in requestedModels) { return; }
var jsonRepo = new JsonRequestService(new RequestJsonRepository(Db, new MemoryCacheProvider()));
foreach (var r in requestedModels)
{
var id = jsonRepo.AddRequest(r);
result.Add(id);
}
}
catch (SqliteException)
{ {
var id = jsonRepo.AddRequest(r); // There is no requested table so they do not have an old version of the DB
result.Add(id); return;
} }
if (result.Any(x => x == -1)) if (result.Any(x => x == -1))

Loading…
Cancel
Save