diff --git a/src/Model/Migration/Definitions.hs b/src/Model/Migration/Definitions.hs index 4cc026a76..470145d6e 100644 --- a/src/Model/Migration/Definitions.hs +++ b/src/Model/Migration/Definitions.hs @@ -179,7 +179,7 @@ customMigrations = mapF $ \case |] Migration20240124UniquenessCompanyAvsNr -> - unlessM (indexExists "unique_company_avs_id") $ do -- companies with avs_id == 0 can be deleted; company users are deleted automatically by cascade + whenM (tableExists "company" `and2M` notM (indexExists "unique_company_avs_id")) $ do -- companies with avs_id == 0 can be deleted; company users are deleted automatically by cascade [executeQQ| DELETE FROM "company" WHERE avs_id = 0; ALTER TABLE "company" DROP CONSTRAINT IF EXISTS "unique_company_shorthand"; diff --git a/src/Utils.hs b/src/Utils.hs index 5ae894f30..54338f381 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -1196,6 +1196,9 @@ ifM c x y = c >>= bool y x ifNotM :: Monad m => m Bool -> m a -> m a -> m a ifNotM c = flip $ ifM c +notM :: Functor f => f Bool -> f Bool +notM = fmap not + -- | Short-circuiting monadic boolean function, copied from Andreas Abel's utility function and2M, or2M :: Monad m => m Bool -> m Bool -> m Bool and2M ma mb = ifM ma mb (return False)