Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
- { name: ruby, script: integration/ruby/run.sh }
- { name: java, script: integration/java/run.sh }
- { name: elixir, script: integration/elixir/run.sh, needs_beam: true }
- { name: haskell, script: integration/haskell/run.sh, needs_haskell: true }
- { name: mirror, script: integration/mirror/run.sh }
- { name: sql, script: integration/sql/run.sh }
- { name: toxi, script: integration/toxi/run.sh }
Expand Down Expand Up @@ -135,6 +136,21 @@ jobs:
with:
otp-version: "28"
elixir-version: "1.20.3"
- name: Install GHC/Cabal
if: matrix.needs_haskell
id: setup-haskell
uses: haskell-actions/setup@v2
with:
ghc-version: "9.12.4"
cabal-version: "latest"
- name: Cache Cabal dependencies
if: matrix.needs_haskell
uses: actions/cache@v5
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: cabal-${{ runner.os }}-${{ steps.setup-haskell.outputs.ghc-version }}-${{ hashFiles('integration/haskell/*.cabal', 'integration/haskell/cabal.project', 'integration/haskell/**/*.hs') }}
restore-keys: |
cabal-${{ runner.os }}-${{ steps.setup-haskell.outputs.ghc-version }}-
- name: Setup dependencies
run: bash integration/ci/setup.sh --with-toxi
- name: Run ${{ matrix.name }}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ edition = "2024"
pgdog-plugin = { path = "./pgdog-plugin", version = "0.4.0", default-features = false }
pgdog-config = { path = "./pgdog-config", version = "0.1.0" }
pgdog-postgres-types = { path = "./pgdog-postgres-types"}
pg_raw_parse = { git = "https://github.com/pgdogdev/pg_raw_parse.git", rev = "8758803" }
pg_raw_parse = { git = "https://github.com/pgdogdev/pg_raw_parse.git", rev = "6870860" }
bon = "3.9"
schemars = { version = "1.2.1", features = ["uuid1"] }
serde_json = "1.0"
Expand Down
1 change: 1 addition & 0 deletions integration/haskell/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist-newstyle/
3 changes: 3 additions & 0 deletions integration/haskell/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages: .

tests: true
29 changes: 29 additions & 0 deletions integration/haskell/dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

pushd "${SCRIPT_DIR}"

has_required_version() {
cabal list persistent-postgresql --simple-output |
grep -Fqx 'persistent-postgresql 2.14.3.0'
}

for attempt in 1 2 3; do
if has_required_version; then
break
fi

echo "Hackage index is stale; refreshing (attempt ${attempt}/3)" >&2
cabal update || true
sleep $((attempt * 5))
done

if ! has_required_version; then
echo "Hackage index does not contain persistent-postgresql 2.14.3.0 after 3 refresh attempts" >&2
exit 1
fi

cabal test --test-show-details=direct
popd
19 changes: 19 additions & 0 deletions integration/haskell/pgdog-haskell-integration.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cabal-version: 3.0
name: pgdog-haskell-integration
version: 0.1.0.0
build-type: Simple

test-suite persistent-integration
type: exitcode-stdio-1.0
main-is: Main.hs
hs-source-dirs: test
default-language: GHC2021
ghc-options: -Wall
build-depends:
base >=4.18 && <5,
hspec >=2.11 && <3,
monad-logger >=0.3 && <0.4,
persistent >=2.18.1 && <2.19,
persistent-postgresql >=2.14.3 && <2.15,
text >=1.2 && <3,
transformers >=0.5 && <0.7
19 changes: 19 additions & 0 deletions integration/haskell/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source "${SCRIPT_DIR}/../common.sh"

bash "${SCRIPT_DIR}/../ci/apt.sh" libpq-dev pkg-config

if ! command -v cabal >/dev/null 2>&1; then
echo "cabal not found. Install GHC and Cabal, then re-run." >&2
exit 1
fi

run_pgdog
wait_for_pgdog

bash ${SCRIPT_DIR}/dev.sh

stop_pgdog
86 changes: 86 additions & 0 deletions integration/haskell/test/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

module Main (main) where

import Control.Exception (bracket_)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Logger (runNoLoggingT)
import Control.Monad.Trans.Reader (runReaderT)
import Data.Text (Text)
import Database.Persist
import Database.Persist.Postgresql
import Database.Persist.TH
import Test.Hspec

share
[mkPersist sqlSettings, mkMigrate "migrateAll"]
[persistLowerCase|
PersistentThing sql=haskell_persistent
value Text
deriving Eq Show
|]

connectionString :: ConnectionString
connectionString = "host=127.0.0.1 port=6432 user=pgdog password=pgdog dbname=pgdog sslmode=disable"

adminConnectionString :: ConnectionString
adminConnectionString = "host=127.0.0.1 port=6432 user=admin password=pgdog dbname=admin sslmode=disable"

main :: IO ()
main =
bracket_
(runAdminCommand "SET read_write_strategy TO 'conservative'")
(runAdminCommand "RELOAD")
runTests

runAdminCommand :: Text -> IO ()
runAdminCommand command = runNoLoggingT $
withPostgresqlConn adminConnectionString $
runReaderT (rawExecute command [])

runTests :: IO ()
runTests = runNoLoggingT $
withPostgresqlPool connectionString 2 $ \pool ->
liftIO $ do
runSqlPool (runMigration migrateAll) pool
hspec $
before_ (runSqlPool clearTestRows pool) $
describe "Persistent through PgDog" $ do
it "connects and runs a typed query" $ do
result <- runSqlPool selectOne pool
result `shouldBe` [Single 1]

it "creates, reads, updates, and deletes a row" $
runSqlPool basicCrud pool

clearTestRows :: SqlPersistT IO ()
clearTestRows = deleteWhere ([] :: [Filter PersistentThing])

selectOne :: SqlPersistT IO [Single Int]
selectOne = rawSql "SELECT 1" []

basicCrud :: SqlPersistT IO ()
basicCrud = do
key <- insert (PersistentThing "created")

created <- get key
liftIO $ created `shouldBe` Just (PersistentThing "created")

update key [PersistentThingValue =. "updated"]
updated <- get key
liftIO $ updated `shouldBe` Just (PersistentThing "updated")

delete key
deleted <- get key
liftIO $ deleted `shouldBe` Nothing
2 changes: 2 additions & 0 deletions pgdog/src/admin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub mod show_bans;
pub mod show_client_memory;
pub mod show_clients;
pub mod show_config;
pub mod show_guc;
pub mod show_instance_id;
pub mod show_listeners;
pub mod show_lists;
Expand Down Expand Up @@ -74,6 +75,7 @@ pub use show_bans::*;
pub use show_client_memory::*;
pub use show_clients::*;
pub use show_config::*;
pub use show_guc::*;
pub use show_instance_id::*;
pub use show_listeners::*;
pub use show_lists::*;
Expand Down
Loading
Loading