Fix RethinkDB restore (#10)

- Also fixed replacement base URL issue
This commit is contained in:
Daniel J. Summers 2022-06-24 08:47:22 -04:00
parent fde06a2e27
commit dfb0ff3b9c
4 changed files with 40 additions and 19 deletions

3
.gitignore vendored
View File

@ -260,4 +260,5 @@ paket-files/
src/MyWebLog/wwwroot/img/daniel-j-summers src/MyWebLog/wwwroot/img/daniel-j-summers
src/MyWebLog/wwwroot/img/bit-badger src/MyWebLog/wwwroot/img/bit-badger
.ionide .ionide
src/MyWebLog/appsettings.Production.json

View File

@ -41,9 +41,6 @@ module private RethinkHelpers =
/// A list of all tables /// A list of all tables
let all = [ Category; Comment; Page; Post; TagMap; Theme; ThemeAsset; WebLog; WebLogUser ] let all = [ Category; Comment; Page; Post; TagMap; Theme; ThemeAsset; WebLog; WebLogUser ]
/// A list of all tables with a webLogId field
let allForWebLog = [ Comment; Post; Category; TagMap; Page; WebLogUser ]
/// Shorthand for the ReQL starting point /// Shorthand for the ReQL starting point
@ -743,19 +740,42 @@ type RethinkDbData (conn : Net.IConnection, config : DataConfig, log : ILogger<R
} }
member _.delete webLogId = backgroundTask { member _.delete webLogId = backgroundTask {
for table in Table.allForWebLog do // Comments should be deleted by post IDs
do! rethink { let! thePostIds = rethink<{| id : string |} list> {
withTable table withTable Table.Post
getAll [ webLogId ] (nameof webLogId) getAll [ webLogId ] (nameof webLogId)
delete pluck [ "id" ]
write; withRetryOnce; ignoreResult conn result; withRetryOnce conn
} }
do! rethink { if not (List.isEmpty thePostIds) then
withTable Table.WebLog let postIds = thePostIds |> List.map (fun it -> it.id :> obj)
get webLogId do! rethink {
delete withTable Table.Comment
write; withRetryOnce; ignoreResult conn getAll postIds "postId"
} delete
write; withRetryOnce; ignoreResult conn
}
// Tag mappings do not have a straightforward webLogId index
do! rethink {
withTable Table.TagMap
between (r.Array (webLogId, r.Minval ())) (r.Array (webLogId, r.Maxval ()))
[ Index "webLogAndTag" ]
delete
write; withRetryOnce; ignoreResult conn
}
for table in [ Table.Post; Table.Category; Table.Page; Table.WebLogUser ] do
do! rethink {
withTable table
getAll [ webLogId ] (nameof webLogId)
delete
write; withRetryOnce; ignoreResult conn
}
do! rethink {
withTable Table.WebLog
get webLogId
delete
write; withRetryOnce; ignoreResult conn
}
} }
member _.findByHost url = member _.findByHost url =

View File

@ -275,7 +275,7 @@ module Backup =
match! data.WebLog.findById archive.webLog.id with match! data.WebLog.findById archive.webLog.id with
| Some webLog when defaultArg newUrlBase webLog.urlBase = webLog.urlBase -> | Some webLog when defaultArg newUrlBase webLog.urlBase = webLog.urlBase ->
do! data.WebLog.delete webLog.id do! data.WebLog.delete webLog.id
return archive return { archive with webLog = { archive.webLog with urlBase = defaultArg newUrlBase webLog.urlBase } }
| Some _ -> | Some _ ->
// Err'body gets new IDs... // Err'body gets new IDs...
let newWebLogId = WebLogId.create () let newWebLogId = WebLogId.create ()

View File

@ -10,7 +10,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Content Include="appsettings.json" CopyToOutputDirectory="Always" /> <Content Include="appsettings*.json" CopyToOutputDirectory="Always" />
<Compile Include="Caches.fs" /> <Compile Include="Caches.fs" />
<Compile Include="Handlers\Error.fs" /> <Compile Include="Handlers\Error.fs" />
<Compile Include="Handlers\Helpers.fs" /> <Compile Include="Handlers\Helpers.fs" />