fix(build): prevent migration on non-existing table

This commit is contained in:
Steffen Jost 2023-07-18 14:58:00 +00:00
parent 21ab898607
commit 5bb49cd889

View File

@ -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)