forked from alevy/postgresql-orm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pg_migrate.hs
34 lines (33 loc) · 1.36 KB
/
pg_migrate.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import Database.PostgreSQL.Migrate
import System.Environment
import System.Exit
import System.FilePath
import System.IO
main :: IO ()
main = do
args <- getArgs
ec <- case args of
"init":[] -> initializeDb >> return ExitSuccess
"dump":[] -> withFile (defaultMigrationsDir </> ".." </> "schema.sql")
WriteMode $ dumpDb
"dump":file:[] -> withFile file WriteMode $ dumpDb
"migrate":[] -> runMigrationsForDir stdout defaultMigrationsDir
"migrate":dir:[] -> runMigrationsForDir stdout dir
"rollback":[] -> runRollbackForDir defaultMigrationsDir
"rollback":dir:[] -> runRollbackForDir dir
"new":name:[] -> newMigration name defaultMigrationsDir >>
return ExitSuccess
"new":name:dir:[] -> newMigration name dir >> return ExitSuccess
"compile":out:[] -> compileMigrationsForDir defaultMigrationsDir out
"compile":out:dir:[] -> compileMigrationsForDir dir out
_ -> do
progName <- getProgName
putStrLn $ "Usage: " ++ progName ++ " migrate|rollback [DIRECTORY]"
putStrLn $ " " ++ progName ++ " compile [PROGRAM] [DIRECTORY]"
putStrLn $ " " ++ progName ++ " init"
putStrLn $ " " ++ progName ++ " dump [FILE]"
putStrLn $ " " ++ progName ++ " new NAME [DIRECTORY]"
return $ ExitFailure 1
if ec == ExitSuccess then
return ()
else exitWith ec