From 8ad2cc1b20788214dcb7e07cfe149c376d902457 Mon Sep 17 00:00:00 2001 From: "Rune K. Svendsen" Date: Wed, 16 Dec 2020 13:47:11 +0100 Subject: [PATCH] add 'showMigration' --- src/Database/Beam/AutoMigrate.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Database/Beam/AutoMigrate.hs b/src/Database/Beam/AutoMigrate.hs index 49a446b..a69b70b 100644 --- a/src/Database/Beam/AutoMigrate.hs +++ b/src/Database/Beam/AutoMigrate.hs @@ -39,6 +39,7 @@ module Database.Beam.AutoMigrate -- * Printing migrations for debugging purposes prettyEditActionDescription, prettyEditSQL, + showMigration, printMigration, printMigrationIO, @@ -571,10 +572,15 @@ createMigration (Right edits) = ExceptT $ do -- | Prints the migration to stdout. Useful for debugging and diagnostic. printMigration :: MonadIO m => Migration m -> m () printMigration m = do + showMigration m >>= liftIO . putStrLn + +-- | Pretty-prints the migration. Useful for debugging and diagnostic. +showMigration :: MonadIO m => Migration m -> m String +showMigration m = do (a, sortedEdits) <- fmap sortEdits <$> runStateT (runExceptT m) mempty case a of Left e -> liftIO $ throwIO e - Right () -> liftIO $ putStrLn (unlines . map displaySyntax $ editsToPgSyntax sortedEdits) + Right () -> return $ unlines $ map displaySyntax $ editsToPgSyntax sortedEdits printMigrationIO :: Migration Pg.Pg -> IO () printMigrationIO mig = Pg.runBeamPostgres (undefined :: Pg.Connection) $ printMigration mig