Skip to content

Commit

Permalink
update pg config
Browse files Browse the repository at this point in the history
  • Loading branch information
nieled committed Jul 23, 2022
1 parent aae288f commit d8647c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
11 changes: 7 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ services:
image: redis:alpine
ports:
- 6379:6379

rabbitmq:
image: rabbitmq:alpine
ports:
ports:
- 5672:5672

db:
image: postgres
ports:
- 5432:5432
environment:
- POSTGRES_DB=uaa
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=
- POSTGRES_USER=uaa
- POSTGRES_PASSWORD=uaa
17 changes: 13 additions & 4 deletions src/Adapter/PostgreSQL/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ import Data.Pool ( Pool
, withResource
)
import Data.Time ( NominalDiffTime )
import Database.PostgreSQL.Simple ( Connection
import Database.PostgreSQL.Simple ( ConnectInfo(..)
, Connection
, Only(Only)
, SqlError
( SqlError
, sqlErrorMsg
, sqlState
)
, close
, connect
, connectPostgreSQL
, defaultConnectInfo
, query
, withTransaction
)
Expand Down Expand Up @@ -55,7 +58,9 @@ type PG r m = (Has State r, MonadReader r m, MonadIO m, MonadThrow m)

-- TODO: add default config
data Config = Config
{ configUrl :: ByteString
{ configDatabase :: String
, configUser :: String
, configPassword :: String
, configStripeCount :: Int
, configMaxOpenConnPerStripe :: Int
, configIdleConnTimeout :: NominalDiffTime
Expand All @@ -77,7 +82,11 @@ withPool config = bracket initPool cleanPool
(configIdleConnTimeout config)
(configMaxOpenConnPerStripe config)
cleanPool = destroyAllResources
openConn = connectPostgreSQL (configUrl config)
openConn = connect defaultConnectInfo
{ connectDatabase = configDatabase config
, connectUser = configUser config
, connectPassword = configPassword config
}
closeConn = close

withConn :: PG r m => (Connection -> IO a) -> m a
Expand Down Expand Up @@ -166,7 +175,7 @@ findEmailFromUserId userId = do
Right email -> return $ Just email
_ ->
throwString
$ "Should not happen, email in DB is not vali: "
$ "Should not happen, email in DB is not valid: "
<> show mail
_ -> return Nothing
where
Expand Down
4 changes: 3 additions & 1 deletion src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ withState action = withKatip $ \le -> do
where
-- TODO: parse from ENV variables
mqCfg = "amqp://guest:guest@localhost:5672/%2F"
pgCfg = PG.Config { PG.configUrl = "postgresql://localhost/uaa"
pgCfg = PG.Config { PG.configDatabase = "uaa"
, PG.configUser = "uaa"
, PG.configPassword = "uaa"
, PG.configStripeCount = 2
, PG.configMaxOpenConnPerStripe = 5
, PG.configIdleConnTimeout = 10
Expand Down

0 comments on commit d8647c4

Please sign in to comment.