diff --git a/src/MyPrayerJournal.ConvertRecurrence/MyPrayerJournal.ConvertRecurrence.fsproj b/src/MyPrayerJournal.ConvertRecurrence/MyPrayerJournal.ConvertRecurrence.fsproj new file mode 100644 index 0000000..88ac1e5 --- /dev/null +++ b/src/MyPrayerJournal.ConvertRecurrence/MyPrayerJournal.ConvertRecurrence.fsproj @@ -0,0 +1,16 @@ + + + + Exe + net6.0 + + + + + + + + + + + diff --git a/src/MyPrayerJournal.ConvertRecurrence/Program.fs b/src/MyPrayerJournal.ConvertRecurrence/Program.fs new file mode 100644 index 0000000..1247406 --- /dev/null +++ b/src/MyPrayerJournal.ConvertRecurrence/Program.fs @@ -0,0 +1,67 @@ +open MyPrayerJournal.Domain +open NodaTime + +/// Request is the identifying record for a prayer request +[] +type OldRequest = { + /// The ID of the request + id : RequestId + /// The time this request was initially entered + enteredOn : Instant + /// The ID of the user to whom this request belongs ("sub" from the JWT) + userId : UserId + /// The time at which this request should reappear in the user's journal by manual user choice + snoozedUntil : Instant + /// The time at which this request should reappear in the user's journal by recurrence + showAfter : Instant + /// The type of recurrence for this request + recurType : string + /// How many of the recurrence intervals should occur between appearances in the journal + recurCount : int16 + /// The history entries for this request + history : History array + /// The notes for this request + notes : Note array + } + +open LiteDB +open MyPrayerJournal.Data + +let db = new LiteDatabase ("Filename=./mpj.db") +Startup.ensureDb db + +/// Map the old recurrence to the new style +let mapRecurrence old = + match old.recurType with + | "Days" -> Days old.recurCount + | "Hours" -> Hours old.recurCount + | "Weeks" -> Weeks old.recurCount + | _ -> Immediate + +/// Map the old request to the new request +let convert old = { + id = old.id + enteredOn = old.enteredOn + userId = old.userId + snoozedUntil = old.snoozedUntil + showAfter = old.showAfter + recurrence = mapRecurrence old + history = Array.toList old.history + notes = Array.toList old.notes + } + +/// Remove the old request, add the converted one (removes recurType / recurCount fields) +let replace (req : Request) = + db.requests.Delete(Mapping.RequestId.toBson req.id) |> ignore + db.requests.Insert(req) |> ignore + db.Checkpoint() + +let reqs = db.GetCollection("request").FindAll() +let rList = reqs |> Seq.toList +let mapped = rList |> List.map convert +//let reqList = mapped |> List.ofSeq + +mapped |> List.iter replace + +// For more information see https://aka.ms/fsharp-console-apps +printfn "Done" diff --git a/src/MyPrayerJournal.ConvertRecurrence/mpj.db b/src/MyPrayerJournal.ConvertRecurrence/mpj.db new file mode 100644 index 0000000..33f5f3d Binary files /dev/null and b/src/MyPrayerJournal.ConvertRecurrence/mpj.db differ diff --git a/src/MyPrayerJournal.sln b/src/MyPrayerJournal.sln new file mode 100644 index 0000000..393866a --- /dev/null +++ b/src/MyPrayerJournal.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MyPrayerJournal", "MyPrayerJournal\MyPrayerJournal.fsproj", "{6BD5A3C8-F859-42A0-ACD7-A5819385E828}" +EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "MyPrayerJournal.ConvertRecurrence", "MyPrayerJournal.ConvertRecurrence\MyPrayerJournal.ConvertRecurrence.fsproj", "{72B57736-8721-4636-A309-49FA4222416E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6BD5A3C8-F859-42A0-ACD7-A5819385E828}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6BD5A3C8-F859-42A0-ACD7-A5819385E828}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6BD5A3C8-F859-42A0-ACD7-A5819385E828}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6BD5A3C8-F859-42A0-ACD7-A5819385E828}.Release|Any CPU.Build.0 = Release|Any CPU + {72B57736-8721-4636-A309-49FA4222416E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {72B57736-8721-4636-A309-49FA4222416E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {72B57736-8721-4636-A309-49FA4222416E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {72B57736-8721-4636-A309-49FA4222416E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal