moved db structure detection at the beginning (2 tests failing)

This commit is contained in:
Ruslan Talpa
2015-09-22 16:56:19 +03:00
parent 6bd6108619
commit a7b883c922
7 changed files with 349 additions and 129 deletions
+17 -1
View File
@@ -30,6 +30,7 @@ import PostgREST.App (app)
import PostgREST.Config (AppConfig(..))
import PostgREST.Middleware
import PostgREST.Error(errResponse)
import PostgREST.PgStructure
isLeft :: Either a b -> Bool
isLeft (Left _ ) = True
@@ -53,10 +54,25 @@ withApp perform = do
pool :: H.Pool P.Postgres
<- H.acquirePool pgSettings testPoolOpts
let txParam = (Just (H.ReadCommitted, Just True))
tblsRes <- H.session pool $ H.tx txParam alltables
let allTables = either (fail . show) id tblsRes
relsRes <- H.session pool $ H.tx txParam allrelations
let allRelations = either (fail . show) id relsRes
colsRes <- H.session pool $ H.tx txParam $ allcolumns allRelations
let allColumns = either (fail . show) id colsRes
pkRes <- H.session pool $ H.tx txParam $ allprimaryKeys
let allPrimaryKeys = either (fail . show) id pkRes
perform $ middle $ \req resp -> do
body <- strictRequestBody req
result <- liftIO $ H.session pool $ H.tx (Just (H.ReadCommitted, Just True))
$ authenticated cfg (app cfg body) req
$ authenticated cfg (app allTables allRelations allColumns allPrimaryKeys cfg body) req
either (resp . errResponse) resp result
where middle = defaultMiddle False