From 5bb49cd88941e510a50759efaad88690f841ca47 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Tue, 18 Jul 2023 14:58:00 +0000 Subject: [PATCH] fix(build): prevent migration on non-existing table --- src/Model/Migration/Definitions.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Model/Migration/Definitions.hs b/src/Model/Migration/Definitions.hs index 2ff047457..7a1d9639e 100644 --- a/src/Model/Migration/Definitions.hs +++ b/src/Model/Migration/Definitions.hs @@ -885,7 +885,7 @@ customMigrations = mapF $ \case |] Migration20230703LmsUserStatus -> - unlessM (columnExists "lms_user" "status_day") $ do + whenM (columnNotExists "lms_user" "status_day") $ do [executeQQ| ALTER TABLE "lms_user" ADD COLUMN "status_day" date; UPDATE "lms_user" @@ -928,3 +928,10 @@ columnExists table column = do case haveColumn :: [Single PersistValue] of [_] -> return True _other -> return False + +-- | equivalent to andM [ tableExists, not <$> columnExists] +columnNotExists :: MonadIO m + => Text -- ^ Table + -> Text -- ^ Column + -> ReaderT SqlBackend m Bool +columnNotExists table column = and2M (tableExists table) (not <$> columnExists table column)