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

Commit 22c5914

Browse files
committed
Rewrite goScripts and go in terms of sequenceMigration
1 parent 6fe9957 commit 22c5914

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
@@ -119,14 +119,8 @@ executeDirectoryMigration :: Connection -> Bool -> FilePath -> IO (MigrationResu
119119
executeDirectoryMigration con verbose dir =
120120
scriptsInDirectory dir >>= go
121121
where
122-
go [] = return MigrationSuccess
123-
go (f:fs) = do
124-
r <- executeMigration con verbose f =<< BS.readFile (dir ++ "/" ++ f)
125-
case r of
126-
MigrationError _ ->
127-
return r
128-
MigrationSuccess ->
129-
go fs
122+
go fs = sequenceMigrations (executeMigrationFile <$> fs)
123+
executeMigrationFile f = executeMigration con verbose f =<< BS.readFile (dir ++ "/" ++ f)
130124

131125
-- | Lists all files in the given 'FilePath' 'dir' in alphabetical order.
132126
scriptsInDirectory :: FilePath -> IO [String]
@@ -207,13 +201,8 @@ executeValidation con verbose cmd = case cmd of
207201
when verbose $ putStrLn $ "Checksum mismatch:\t" ++ name
208202
return (MigrationError $ "Checksum mismatch: " ++ name)
209203

210-
goScripts _ [] = return MigrationSuccess
211-
goScripts path (x:xs) =
212-
(validate x =<< BS.readFile (path ++ "/" ++ x)) >>= \case
213-
e@(MigrationError _) ->
214-
return e
215-
MigrationSuccess ->
216-
goScripts path xs
204+
goScripts path xs = sequenceMigrations (goScript path <$> xs)
205+
goScript path x = validate x =<< BS.readFile (path ++ "/" ++ x)
217206

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

0 commit comments

Comments
 (0)