-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.idr
48 lines (39 loc) · 1.42 KB
/
Main.idr
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module Main
import Control.IOExcept
import Data.IORef
import Dbcritic.Check
import Dbcritic.Check.IndexFkRef
import Dbcritic.Check.PrimaryKey
import Dbcritic.Check.PrimaryKeyBigint
import Dbcritic.Check.TimeZone
import Dbcritic.Check.Timestamptz
import Dbcritic.Config
import Dbcritic.Libpq
import System
checks : List Check
checks = [ checkIndexFkRef, checkPrimaryKey, checkPrimaryKeyBigint, checkTimeZone, checkTimestamptz ]
main' : IOExcept String Int
main' = do
config <- readConfig ".dbcriticrc"
conn <- pgConnect ""
index <- ioe_lift $ newIORef 0
for_ checks $ \check => do
allIssues <- inspect check conn
let allSilences = getSilences config check
let issues = filter (not . isSilenced allSilences) allIssues
let unsilence = filter (not . silencesIssue allIssues) allSilences
for_ issues $ \issue => do
index' <- ioe_lift $ modifyIORef index (+ 1) *> readIORef index
ioe_lift $ putStrLn (formatIssue index' check issue)
for_ unsilence $ \silence => do
index' <- ioe_lift $ modifyIORef index (+ 1) *> readIORef index
ioe_lift $ putStrLn (formatSilence index' silence)
count <- ioe_lift $ readIORef index
pure $ if count > 0 then 1 else 0
main : IO ()
main = do
result <- runIOExcept main'
case result of
Right n => exit n
Left err => do fPutStrLn stderr err
exit 2