connect to db via local socket
This commit is contained in:
parent
d7cca298bd
commit
490b6211f0
@ -53,8 +53,9 @@ testUsers =
|
|||||||
|
|
||||||
runDB :: ReaderT SqlBackend (NoLoggingT (ResourceT IO)) a -> IO a
|
runDB :: ReaderT SqlBackend (NoLoggingT (ResourceT IO)) a -> IO a
|
||||||
runDB action = do
|
runDB action = do
|
||||||
Just port <- lookupEnv "OAUTH2_DB_PORT" >>= \p -> return $ p <|> Just "9444"
|
Just port <- lookupEnv "OAUTH2_DB_PORT" -- >>= \p -> return $ p <|> Just "9444"
|
||||||
let connStr = fromString @ConnectionString $ "host=localhost dbname=test_users user=oauth2mock password=0000 port=" ++ port
|
Just host <- lookupEnv "PGHOST"
|
||||||
|
let connStr = fromString @ConnectionString $ "host=" ++ host ++ " dbname=test_users user=oauth2mock password=0000 port=" ++ port
|
||||||
runStderrLoggingT $ withPostgresqlPool connStr 10 $ \pool -> liftIO $ flip runSqlPersistMPool pool action
|
runStderrLoggingT $ withPostgresqlPool connStr 10 $ \pool -> liftIO $ flip runSqlPersistMPool pool action
|
||||||
|
|
||||||
initDB :: IO ()
|
initDB :: IO ()
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
devShells.${system}.default = pkgs.mkShell {
|
devShells.${system}.default = pkgs.mkShell {
|
||||||
buildInputs = buildInputs;
|
buildInputs = buildInputs;
|
||||||
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
|
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
|
||||||
shellHook = "./mkDB.sh";
|
shellHook = builtins.readFile ./mkDB.sh;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
14
mkDB.sh
Normal file → Executable file
14
mkDB.sh
Normal file → Executable file
@ -1,5 +1,3 @@
|
|||||||
#!/bin/sh -e
|
|
||||||
|
|
||||||
export OAUTH2_SERVER_PORT=9443
|
export OAUTH2_SERVER_PORT=9443
|
||||||
export OAUTH2_DB_PORT=9444
|
export OAUTH2_DB_PORT=9444
|
||||||
|
|
||||||
@ -9,13 +7,15 @@ if [ ! -d "${tmpdir}" ]; then
|
|||||||
mkdir ${tmpdir}
|
mkdir ${tmpdir}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pgDir=$(mktemp -d --tmpdir="${tmpdir}" postgresql.XXXXXX)
|
absdir=$(realpath ${tmpdir})
|
||||||
pgSockDir=$(mktemp -d --tmpdir="${tmpdir}" postgresql.sock.XXXXXX)
|
|
||||||
pgLogFile=$(mktemp --tmpdir="${tmpdir}" postgresql.XXXXXX.log)
|
pgDir=$(mktemp -d --tmpdir="${absdir}" postgresql.XXXXXX)
|
||||||
|
pgSockDir=$(mktemp -d --tmpdir="${absdir}" postgresql.sock.XXXXXX)
|
||||||
|
pgLogFile=$(mktemp --tmpdir="${absdir}" postgresql.XXXXXX.log)
|
||||||
|
|
||||||
initdb --no-locale -D "${pgDir}"
|
initdb --no-locale -D "${pgDir}"
|
||||||
pg_ctl start -D "${pgDir}" -l "${pgLogFile}" -w -o "-k ${pgSockDir} -c listen_addresses=''' -c hba_file='hba_file' -p ${OAUTH2_DB_PORT} -h localhost -c unix_socket_permissions=0700 -c max_connections=10 -c session_preload_libraries=auto_explain -c auto_explain.log_min_duration=100ms"
|
pg_ctl start -D "${pgDir}" -l "${pgLogFile}" -w -o "-k ${pgSockDir} -c listen_addresses='::' -c hba_file='hba_file' -p ${OAUTH2_DB_PORT} -h localhost -c unix_socket_permissions=0700 -c max_connections=10 -c session_preload_libraries=auto_explain -c auto_explain.log_min_duration=100ms"
|
||||||
psql -h "${pgSockDir}" -f ./schema.sql postgres
|
psql -h "${pgSockDir}" -p ${OAUTH2_DB_PORT} -f ./schema.sql postgres
|
||||||
|
|
||||||
printf "Postgres logfile is %s\nPostgres socket directory is %s\n" "${pgLogFile}" "${pgSockDir}"
|
printf "Postgres logfile is %s\nPostgres socket directory is %s\n" "${pgLogFile}" "${pgSockDir}"
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user