pg-migrate-test-support 1.1.0.0 → 1.2.0.0
raw patch · 4 files changed
+84/−31 lines, 4 filesdep +directorydep +unixdep ~ephemeral-pgdep ~pg-migratePVP ok
version bump matches the API change (PVP)
Dependencies added: directory, unix
Dependency ranges changed: ephemeral-pg, pg-migrate
API changes (from Hackage documentation)
+ Database.PostgreSQL.Migrate.Test: defaultEphemeralConfig :: IO Config
Files
- CHANGELOG.md +24/−0
- pg-migrate-test-support.cabal +33/−29
- src/Database/PostgreSQL/Migrate/Test.hs +25/−1
- test/Main.hs +2/−1
CHANGELOG.md view
@@ -1,5 +1,29 @@ # Changelog +## 1.2.0.0 — 2026-09-18++Major release: `withMigratedDatabaseConfig` takes an `EphemeralPg.Config`, and this set moves+to ephemeral-pg 0.3, whose `Config` gained a field.++### Breaking changes++- Require `ephemeral-pg >=0.3.1 && <0.4` (was `>=0.2 && <0.3`). ephemeral-pg 0.3 added+ `sweepStaleOnStart` to `Config`, so callers that construct `Config` exhaustively must+ set it; ephemeral-pg 0.3.1 also reclaims clusters abandoned by killed runs on the next+ startup.++### New features++- Add `defaultEphemeralConfig`, which pins ephemeral-pg's `temporaryRoot` to a stable+ per-user directory (`/tmp/ephpg-pg-migrate-<uid>`, created if missing). Start from it+ when calling `withMigratedDatabaseConfig`.++### Fixes and behavior changes++- `withMigratedDatabase` and `withMigratedDatabaseOptions` now use `defaultEphemeralConfig`,+ so the stale-cluster sweep keeps working under a per-session `$TMPDIR` (`nix develop`,+ `nix-shell`, CI runners).+ ## 1.1.0.0 — 2026-07-13 Major release: this set removes a public error constructor and changes callback exception
pg-migrate-test-support.cabal view
@@ -1,19 +1,19 @@-cabal-version: 3.8-name: pg-migrate-test-support-version: 1.1.0.0-synopsis: Ephemeral PostgreSQL helpers for pg-migrate tests-category: Database-maintainer: nadeem@gmail.com+cabal-version: 3.8+name: pg-migrate-test-support+version: 1.2.0.0+synopsis: Ephemeral PostgreSQL helpers for pg-migrate tests+category: Database+maintainer: nadeem@gmail.com description: Brackets an ephemeral PostgreSQL instance, applies a validated migration plan, and supplies a fresh Hasql connection to a test callback. -license: BSD-3-Clause-build-type: Simple+license: BSD-3-Clause+build-type: Simple extra-doc-files: CHANGELOG.md common common- default-language: GHC2024+ default-language: GHC2024 default-extensions: DeriveAnyClass DuplicateRecordFields@@ -21,31 +21,35 @@ OverloadedLabels OverloadedStrings - ghc-options: -Wall -Wcompat+ ghc-options:+ -Wall+ -Wcompat library- import: common- hs-source-dirs: src+ import: common+ hs-source-dirs: src exposed-modules: Database.PostgreSQL.Migrate.Test build-depends:- , base >=4.20 && <4.22- , ephemeral-pg >=0.2 && <0.3- , hasql >=1.10 && <1.11- , pg-migrate >=1.1 && <1.2+ base >=4.20 && <4.22,+ directory >=1.3 && <1.4,+ ephemeral-pg >=0.3.1 && <0.4,+ hasql >=1.10 && <1.11,+ pg-migrate >=1.2 && <1.3,+ unix >=2.8 && <2.9, test-suite pg-migrate-test-support-test- import: common- type: exitcode-stdio-1.0+ import: common+ type: exitcode-stdio-1.0 hs-source-dirs: test- main-is: Main.hs+ main-is: Main.hs build-depends:- , base >=4.20 && <4.22- , bytestring >=0.12 && <0.13- , containers >=0.7 && <0.8- , ephemeral-pg >=0.2 && <0.3- , hasql >=1.10 && <1.11- , pg-migrate- , pg-migrate-test-support- , tasty >=1.5 && <1.6- , tasty-hunit >=0.10 && <0.11- , text >=2.1 && <2.2+ base >=4.20 && <4.22,+ bytestring >=0.12 && <0.13,+ containers >=0.7 && <0.8,+ ephemeral-pg >=0.3.1 && <0.4,+ hasql >=1.10 && <1.11,+ pg-migrate,+ pg-migrate-test-support,+ tasty >=1.5 && <1.6,+ tasty-hunit >=0.10 && <0.11,+ text >=2.1 && <2.2,
src/Database/PostgreSQL/Migrate/Test.hs view
@@ -9,16 +9,22 @@ withMigratedDatabaseOptions, -- | Fully configurable ephemeral-database variant. withMigratedDatabaseConfig,+ -- | Default ephemeral-database configuration with a stable per-user temporary root.+ defaultEphemeralConfig, ) where import Control.Exception (SomeException) import Control.Exception qualified as Exception+import Data.Monoid (Last (..)) import Database.PostgreSQL.Migrate import EphemeralPg qualified+import EphemeralPg.Config qualified import Hasql.Connection qualified as Connection import Hasql.Connection.Settings qualified as Settings import Hasql.Errors qualified as Errors+import System.Directory (createDirectoryIfMissing)+import System.Posix.User (getEffectiveUserID) -- | Structured failures from the ephemeral database, migration, callback, or a callback -- failure accompanied by a connection-release failure. A release failure after a@@ -44,7 +50,25 @@ MigrationPlan -> (Connection.Connection -> IO value) -> IO (Either MigratedDatabaseError value)-withMigratedDatabaseOptions = withMigratedDatabaseConfig EphemeralPg.defaultConfig+withMigratedDatabaseOptions options plan callback = do+ config <- defaultEphemeralConfig+ withMigratedDatabaseConfig config options plan callback++-- | 'EphemeralPg.defaultConfig' with @temporaryRoot@ pinned to+-- @\/tmp\/ephpg-pg-migrate-\<uid\>@, created if missing.+--+-- An unset root resolves to @$TMPDIR@, which @nix develop@, @nix-shell@, and many CI+-- runners allocate per session; ephemeral-pg's startup sweep then never sees clusters+-- abandoned by earlier killed runs. A root that is stable per effective uid keeps the+-- sweep effective while keeping build sandboxes running as another uid out of a+-- developer-owned @0700@ directory. Extend this rather than 'EphemeralPg.defaultConfig'+-- when calling 'withMigratedDatabaseConfig'.+defaultEphemeralConfig :: IO EphemeralPg.Config+defaultEphemeralConfig = do+ uid <- getEffectiveUserID+ let root = "/tmp/ephpg-pg-migrate-" <> show uid+ createDirectoryIfMissing True root+ pure EphemeralPg.defaultConfig {EphemeralPg.Config.temporaryRoot = Last (Just root)} -- | Fully configurable variant accepting both ephemeral database and migration options. -- Asynchronous callback exceptions are rethrown after releasing the callback connection.
test/Main.hs view
@@ -65,7 +65,8 @@ testStartupFailure :: Assertion testStartupFailure = do- let invalidConfig = EphemeralPg.Config.defaultConfig {EphemeralPg.Config.initDbArgs = ["--definitely-invalid-initdb-option"]}+ baseConfig <- defaultEphemeralConfig+ let invalidConfig = baseConfig {EphemeralPg.Config.initDbArgs = ["--definitely-invalid-initdb-option"]} result <- withMigratedDatabaseConfig invalidConfig defaultRunOptions fixturePlan (const (pure ())) case result of Left MigratedDatabaseStartupFailed {} -> pure ()