diff --git a/src/MyPrayerJournal.ToPostgres/Program.fs b/src/MyPrayerJournal.ToPostgres/Program.fs index d1b4ad3..fff4a16 100644 --- a/src/MyPrayerJournal.ToPostgres/Program.fs +++ b/src/MyPrayerJournal.ToPostgres/Program.fs @@ -1,9 +1,33 @@ open LiteDB +open MyPrayerJournal.Data open MyPrayerJournal.Domain open MyPrayerJournal.LiteData +open Microsoft.Extensions.Configuration let lite = new LiteDatabase "Filename=./mpj.db" Startup.ensureDb lite +let cfg = (ConfigurationBuilder().AddJsonFile "appsettings.json").Build () +Connection.setUp cfg |> Async.AwaitTask |> Async.RunSynchronously + +let reqs = lite.Requests.FindAll () + +reqs +|> Seq.map (fun old -> + { Request.empty with + Id = old.Id + EnteredOn = old.EnteredOn + UserId = old.UserId + SnoozedUntil = old.SnoozedUntil + ShowAfter = old.ShowAfter + Recurrence = old.Recurrence + History = old.History |> Array.sortByDescending (fun it -> it.AsOf) |> List.ofArray + Notes = old.Notes |> Array.sortByDescending (fun it -> it.AsOf) |> List.ofArray + }) +|> Seq.map Request.add +|> List.ofSeq +|> List.iter (Async.AwaitTask >> Async.RunSynchronously) + +System.Console.WriteLine $"Migration complete - {Seq.length reqs} requests migrated" diff --git a/src/MyPrayerJournal/Data.fs b/src/MyPrayerJournal/Data.fs index a8102a3..4b0345f 100644 --- a/src/MyPrayerJournal/Data.fs +++ b/src/MyPrayerJournal/Data.fs @@ -36,7 +36,8 @@ module Json = ] |> List.iter opts.Converters.Add let _ = opts.ConfigureForNodaTime NodaTime.DateTimeZoneProviders.Tzdb - opts.PropertyNamingPolicy <- JsonNamingPolicy.CamelCase + opts.PropertyNamingPolicy <- JsonNamingPolicy.CamelCase + opts.DefaultIgnoreCondition <- JsonIgnoreCondition.WhenWritingNull opts @@ -165,9 +166,9 @@ module Journal = return reqs |> Seq.ofList - |> Seq.map JournalRequest.ofRequestFull - |> Seq.filter (fun it -> it.LastStatus = Answered) - |> Seq.sortByDescending (fun it -> it.AsOf) + |> Seq.map JournalRequest.ofRequestLite + |> Seq.filter (fun it -> it.LastStatus <> Answered) + |> Seq.sortBy (fun it -> it.AsOf) |> List.ofSeq } diff --git a/src/MyPrayerJournal/appsettings.json b/src/MyPrayerJournal/appsettings.json index 2e2d592..817bfde 100644 --- a/src/MyPrayerJournal/appsettings.json +++ b/src/MyPrayerJournal/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "db": "Filename=./mpj.db" + "mpj": "host=localhost;username=mpj;password=devpassword;database=mpj" }, "Kestrel": { "EndPoints": {