Skip to content

Commit

Permalink
add 'showMigration'
Browse files Browse the repository at this point in the history
  • Loading branch information
runeksvendsen committed Dec 16, 2020
1 parent e57d339 commit 8ad2cc1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Database/Beam/AutoMigrate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module Database.Beam.AutoMigrate
-- * Printing migrations for debugging purposes
prettyEditActionDescription,
prettyEditSQL,
showMigration,
printMigration,
printMigrationIO,

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8ad2cc1

Please sign in to comment.