Add person data access, integ tests, backup/restore (#17)

This commit is contained in:
2026-08-02 22:09:03 -04:00
parent d9e7c771ba
commit 5c7d34ffc7
16 changed files with 345 additions and 22 deletions
+24 -7
View File
@@ -229,6 +229,9 @@ module Backup =
/// The pages for this web log (containing only the most recent revision)
Pages: Page list
/// The person entries for this web log
People: Person list
/// The posts for this web log (containing only the most recent revision)
Posts: Post list
@@ -249,6 +252,7 @@ module Backup =
let categoryCount = List.length archive.Categories
let tagMapCount = List.length archive.TagMappings
let pageCount = List.length archive.Pages
let personCount = List.length archive.People
let postCount = List.length archive.Posts
let uploadCount = List.length archive.Uploads
@@ -263,6 +267,7 @@ module Backup =
printfn $""" - {categoryCount} categor{plural categoryCount "y" "ies"}"""
printfn $""" - {tagMapCount} tag mapping{plural tagMapCount "" "s"}"""
printfn $""" - {pageCount} page{plural pageCount "" "s"}"""
printfn $""" - {personCount} people"""
printfn $""" - {postCount} post{plural postCount "" "s"}"""
printfn $""" - {uploadCount} uploaded file{plural uploadCount "" "s"}"""
@@ -283,6 +288,9 @@ module Backup =
printfn "- Exporting pages..."
let! pages = data.Page.FindFullByWebLog webLog.Id
printfn "- Exporting people..."
let! people = data.Person.FindByWebLog webLog.Id
printfn "- Exporting posts..."
let! posts = data.Post.FindFullByWebLog webLog.Id
@@ -298,6 +306,7 @@ module Backup =
Categories = categories
TagMappings = tagMaps
Pages = pages |> List.map (fun p -> { p with Revisions = List.truncate 1 p.Revisions })
People = people
Posts = posts |> List.map (fun p -> { p with Revisions = List.truncate 1 p.Revisions })
Uploads = uploads |> List.map EncodedUpload.fromUpload }
@@ -319,15 +328,17 @@ module Backup =
return { archive with Archive.WebLog.UrlBase = defaultArg newUrlBase webLog.UrlBase }
| Some _ ->
// Err'body gets new IDs...
let newWebLogId = WebLogId.Create()
let newCatIds = archive.Categories |> List.map (fun cat -> cat.Id, CategoryId.Create() ) |> dict
let newMapIds = archive.TagMappings |> List.map (fun tm -> tm.Id, TagMapId.Create() ) |> dict
let newPageIds = archive.Pages |> List.map (fun page -> page.Id, PageId.Create() ) |> dict
let newPostIds = archive.Posts |> List.map (fun post -> post.Id, PostId.Create() ) |> dict
let newUserIds = archive.Users |> List.map (fun user -> user.Id, WebLogUserId.Create()) |> dict
let newUpIds = archive.Uploads |> List.map (fun up -> up.Id, UploadId.Create() ) |> dict
let newWebLogId = WebLogId.Create()
let newCatIds = archive.Categories |> List.map (fun cat -> cat.Id, CategoryId.Create() ) |> dict
let newMapIds = archive.TagMappings |> List.map (fun tm -> tm.Id, TagMapId.Create() ) |> dict
let newPageIds = archive.Pages |> List.map (fun page -> page.Id, PageId.Create() ) |> dict
let newPersonIds = archive.People |> List.map (fun psn -> psn.Id, PersonId.Create() ) |> dict
let newPostIds = archive.Posts |> List.map (fun post -> post.Id, PostId.Create() ) |> dict
let newUserIds = archive.Users |> List.map (fun user -> user.Id, WebLogUserId.Create()) |> dict
let newUpIds = archive.Uploads |> List.map (fun up -> up.Id, UploadId.Create() ) |> dict
return
{ archive with
// TODO: person IDs should be updated in podcasts and episodes
WebLog = { archive.WebLog with Id = newWebLogId; UrlBase = Option.get newUrlBase }
Users = archive.Users
|> List.map (fun u -> { u with Id = newUserIds[u.Id]; WebLogId = newWebLogId })
@@ -341,6 +352,9 @@ module Backup =
Id = newPageIds[page.Id]
WebLogId = newWebLogId
AuthorId = newUserIds[page.AuthorId] })
People = archive.People
|> List.map (fun person ->
{ person with Id = newPersonIds[person.Id]; WebLogId = newWebLogId })
Posts = archive.Posts
|> List.map (fun post ->
{ post with
@@ -381,6 +395,9 @@ module Backup =
if isInteractive then printfn "- Restoring pages..."
if not (List.isEmpty restore.Pages) then do! data.Page.Restore restore.Pages
if isInteractive then printfn "- Restoring people..."
if not (List.isEmpty restore.People) then do! data.Person.Restore restore.People
if isInteractive then printfn "- Restoring posts..."
if not (List.isEmpty restore.Posts) then do! data.Post.Restore restore.Posts