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

Commit bd60e7f

Browse files
committed
Rewrite goScripts and go in terms of sequenceMigration
1 parent 612d1ef commit bd60e7f

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/Database/PostgreSQL/Simple/Migration.hs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,8 @@ executeDirectoryMigration :: Connection -> Bool -> FilePath -> IO (MigrationResu
114114
executeDirectoryMigration con verbose dir =
115115
scriptsInDirectory dir >>= go
116116
where
117-
go [] = return MigrationSuccess
118-
go (f:fs) = do
119-
r <- executeMigration con verbose f =<< BS.readFile (dir ++ "/" ++ f)
120-
case r of
121-
MigrationError _ ->
122-
return r
123-
MigrationSuccess ->
124-
go fs
117+
go fs = sequenceMigrations (executeMigrationFile <$> fs)
118+
executeMigrationFile f = executeMigration con verbose f =<< BS.readFile (dir ++ "/" ++ f)
125119

126120
-- | Lists all files in the given 'FilePath' 'dir' in alphabetical order.
127121
scriptsInDirectory :: FilePath -> IO [String]
@@ -202,13 +196,8 @@ executeValidation con verbose cmd = case cmd of
202196
when verbose $ putStrLn $ "Checksum mismatch:\t" ++ name
203197
return (MigrationError $ "Checksum mismatch: " ++ name)
204198

205-
goScripts _ [] = return MigrationSuccess
206-
goScripts path (x:xs) =
207-
(validate x =<< BS.readFile (path ++ "/" ++ x)) >>= \case
208-
e@(MigrationError _) ->
209-
return e
210-
MigrationSuccess ->
211-
goScripts path xs
199+
goScripts path xs = sequenceMigrations (goScript path <$> xs)
200+
goScript path x = validate x =<< BS.readFile (path ++ "/" ++ x)
212201

213202
-- | Checks the status of the script with the given name 'name'.
214203
-- If the script has already been executed, the checksum of the script

0 commit comments

Comments
 (0)