From dfb0ff3b9c314929c029560daf18851c2edbe4b3 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Fri, 24 Jun 2022 08:47:22 -0400 Subject: [PATCH] Fix RethinkDB restore (#10) - Also fixed replacement base URL issue --- .gitignore | 3 +- src/MyWebLog.Data/RethinkDbData.fs | 52 +++++++++++++++++++++--------- src/MyWebLog/Maintenance.fs | 2 +- src/MyWebLog/MyWebLog.fsproj | 2 +- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 349e76c..0130e86 100644 --- a/.gitignore +++ b/.gitignore @@ -260,4 +260,5 @@ paket-files/ src/MyWebLog/wwwroot/img/daniel-j-summers src/MyWebLog/wwwroot/img/bit-badger -.ionide \ No newline at end of file +.ionide +src/MyWebLog/appsettings.Production.json diff --git a/src/MyWebLog.Data/RethinkDbData.fs b/src/MyWebLog.Data/RethinkDbData.fs index 4357247..f42e277 100644 --- a/src/MyWebLog.Data/RethinkDbData.fs +++ b/src/MyWebLog.Data/RethinkDbData.fs @@ -41,9 +41,6 @@ module private RethinkHelpers = /// A list of all tables 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 @@ -743,19 +740,42 @@ type RethinkDbData (conn : Net.IConnection, config : DataConfig, log : ILogger { + withTable Table.Post + getAll [ webLogId ] (nameof webLogId) + pluck [ "id" ] + result; withRetryOnce conn + } + if not (List.isEmpty thePostIds) then + let postIds = thePostIds |> List.map (fun it -> it.id :> obj) + do! rethink { + withTable Table.Comment + 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 = diff --git a/src/MyWebLog/Maintenance.fs b/src/MyWebLog/Maintenance.fs index 05ad0bc..6a0f718 100644 --- a/src/MyWebLog/Maintenance.fs +++ b/src/MyWebLog/Maintenance.fs @@ -275,7 +275,7 @@ module Backup = match! data.WebLog.findById archive.webLog.id with | Some webLog when defaultArg newUrlBase webLog.urlBase = webLog.urlBase -> do! data.WebLog.delete webLog.id - return archive + return { archive with webLog = { archive.webLog with urlBase = defaultArg newUrlBase webLog.urlBase } } | Some _ -> // Err'body gets new IDs... let newWebLogId = WebLogId.create () diff --git a/src/MyWebLog/MyWebLog.fsproj b/src/MyWebLog/MyWebLog.fsproj index 972572c..128f153 100644 --- a/src/MyWebLog/MyWebLog.fsproj +++ b/src/MyWebLog/MyWebLog.fsproj @@ -10,7 +10,7 @@ - +