Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit dabdbc1

Browse files
committed
Propagate migration and validation results to application exit code.
Fixes #7.
1 parent ae738d9 commit dabdbc1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Main.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ module Main (
2121
import Control.Applicative
2222
#endif
2323
import Control.Exception
24-
import Control.Monad (void)
2524
import qualified Data.ByteString.Char8 as BS8 (pack)
2625
import Database.PostgreSQL.Simple (SqlError (..),
2726
connectPostgreSQL,
2827
withTransaction)
2928
import Database.PostgreSQL.Simple.Migration (MigrationCommand (..),
3029
MigrationContext (..),
30+
MigrationResult (..),
3131
runMigration)
3232
import System.Environment (getArgs)
33-
import System.Exit (exitFailure)
33+
import System.Exit (exitFailure, exitSuccess)
3434

3535
import qualified Data.Text as T
3636
import qualified Data.Text.Encoding as T
@@ -68,7 +68,7 @@ ppException a = catch a ehandler
6868
run :: Maybe Command -> Bool-> IO ()
6969
run Nothing _ = printUsage >> exitFailure
7070
run (Just cmd) verbose =
71-
void $ case cmd of
71+
handleResult =<< case cmd of
7272
Initialize url -> do
7373
con <- connectPostgreSQL (BS8.pack url)
7474
withTransaction con $ runMigration $ MigrationContext
@@ -81,6 +81,9 @@ run (Just cmd) verbose =
8181
con <- connectPostgreSQL (BS8.pack url)
8282
withTransaction con $ runMigration $ MigrationContext
8383
(MigrationValidation (MigrationDirectory dir)) verbose con
84+
where
85+
handleResult MigrationSuccess = exitSuccess
86+
handleResult (MigrationError _) = exitFailure
8487

8588
parseCommand :: [String] -> Maybe Command
8689
parseCommand ("init":url:_) = Just (Initialize url)

0 commit comments

Comments
 (0)