Add with-db.sh script

This commit is contained in:
Paul Brinkmeier 2025-07-20 01:40:07 +02:00
parent a499c35d5b
commit 1a6d2cadad
4 changed files with 20 additions and 2 deletions

View File

@ -0,0 +1,2 @@
# yore

View File

@ -2,13 +2,14 @@
module Main (main) where
import Control.Exception (bracket)
import qualified Database.PostgreSQL.Opium as Opium
import qualified Yore.DB
main :: IO ()
main = do
conn <- Opium.connect "host=localhost port=5432"
main = bracket (Opium.connect "host=localhost port=5432 user=yore-test dbname=yore-test") Opium.close $ \conn -> do
result <- Yore.DB.getTables conn
case result of

View File

@ -73,6 +73,7 @@
pkgs.cabal-install
pkgs.haskellPackages.implicit-hie
pkgs.haskell-language-server
pkgs.postgresql
];
overrides = addOpium;
}).env;

14
with-db.sh Executable file
View File

@ -0,0 +1,14 @@
BASE_DIR=$(mktemp -d)
export PGDATA="$BASE_DIR/pgdata"
# On error or exit: Stop the DB server
stop_db_server() {
pg_ctl stop --wait
}
trap stop_db_server EXIT
initdb --username=yore-test --auth=trust
pg_ctl start --wait
createdb yore-test --username=yore-test
"$@"