diff --git a/README.md b/README.md index e69de29..5353bb4 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,2 @@ +# yore + diff --git a/app/Main.hs b/app/Main.hs index 23209b7..afbc5a7 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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 diff --git a/flake.nix b/flake.nix index 9d08b9f..8b97196 100644 --- a/flake.nix +++ b/flake.nix @@ -73,6 +73,7 @@ pkgs.cabal-install pkgs.haskellPackages.implicit-hie pkgs.haskell-language-server + pkgs.postgresql ]; overrides = addOpium; }).env; diff --git a/with-db.sh b/with-db.sh new file mode 100755 index 0000000..f10d509 --- /dev/null +++ b/with-db.sh @@ -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 + +"$@"