packages feed

relocant 1.0.0 → 1.1.0

raw patch · 5 files changed

+46/−9 lines, 5 files

Files

CHANGELOG.markdown view
@@ -1,3 +1,10 @@+1.1.0+=====++  * Supported GHC 9.8.4++  * Supported running empty migration scripts.+ 1.0.0 ===== 
relocant.cabal view
@@ -1,11 +1,11 @@ cabal-version: 2.0 --- This file has been generated from package.yaml by hpack version 0.36.0.+-- This file has been generated from package.yaml by hpack version 0.38.0. -- -- see: https://github.com/sol/hpack  name:           relocant-version:        1.0.0+version:        1.1.0 synopsis:       A PostgreSQL migration CLI tool and library description:    relocant documentation is at https://github.com/supki/relocant author:         Matvey Aksenov@@ -62,7 +62,7 @@       OverloadedStrings       OverloadedRecordDot       StrictData-  ghc-options: -funbox-strict-fields -Wall -Wno-incomplete-uni-patterns+  ghc-options: -funbox-strict-fields -Wall -Wcompat -Wno-incomplete-uni-patterns   build-depends:       aeson     , base >=4.18 && <5@@ -93,7 +93,7 @@       OverloadedStrings       OverloadedRecordDot       StrictData-  ghc-options: -Wall -Wno-incomplete-uni-patterns -threaded -with-rtsopts=-N+  ghc-options: -Wall -Wcompat -Wno-incomplete-uni-patterns -threaded -with-rtsopts=-N   build-depends:       base >=4.18 && <5     , relocant@@ -121,7 +121,7 @@       OverloadedStrings       OverloadedRecordDot       StrictData-  ghc-options: -freduction-depth=0 -Wall -Wno-incomplete-uni-patterns -threaded -with-rtsopts=-N+  ghc-options: -freduction-depth=0 -Wall -Wcompat -Wno-incomplete-uni-patterns -threaded -with-rtsopts=-N   build-depends:       base >=4.18 && <5     , bytestring
src/Relocant.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE DuplicateRecordFields #-} -- | A PostgreSQL migration library module Relocant   ( Script(..)
src/Relocant/Script.hs view
@@ -17,6 +17,7 @@   , readContent   ) where +import Control.Exception (catch, throwIO) import "crypton" Crypto.Hash (hash) import Data.Aeson qualified as Aeson import Data.Aeson ((.=))@@ -124,9 +125,23 @@ -- -- /Note:/ You probably want to run this together with 'Relocant.Applied.record' -- in a single transaction.+-- /Note:/ This has to run inside a transaction context, will error out otherwise. apply :: Script -> DB.Connection -> IO Applied apply s conn = do-  applyWith (Duration.measure_ . DB.execute_ conn . DB.Query) s+  applyWith (Duration.measure_ . execute_ conn . DB.Query) s++-- Like DB.execute_, but ignores empty query errors.+execute_ :: DB.Connection -> DB.Query -> IO ()+execute_ conn query = do+  _ <- DB.withSavepoint conn (DB.execute_ conn query)+  pure ()+ `catch`+  \exc ->+    case exc of+      DB.QueryError {DB.qeMessage = "execute: Empty query"} ->+        pure ()+      _ ->+        throwIO exc  -- | Get an 'Applied' migration from a 'Script', without running it. This should not -- be normally used, but can be useful for fixing checksums after cosmetics updates
test/Relocant/ScriptSpec.hs view
@@ -3,6 +3,7 @@ {-# LANGUAGE TypeApplications #-} module Relocant.ScriptSpec (spec) where +import Database.PostgreSQL.Simple (withTransaction) import Prelude hiding (id) import System.FilePath ((</>)) import System.IO.Temp@@ -91,7 +92,7 @@           ]    around DB.withTemplateCloned $ do-    describe "apply" $+    describe "apply" $ do       it "runs a migration script" $ \conn -> do         let           script = Script@@ -99,5 +100,18 @@             , name = "00-oops"             , content = "CREATE TABLE foo ()"             }-        _durationS <- apply script conn-        pure ()+        withTransaction conn $ do+          _durationS <- apply script conn+          pure ()++      context "empty script" $+        it "runs a migration script" $ \conn -> do+          let+            script = Script+              { id = "00"+              , name = "00-oops"+              , content = ""+              }+          withTransaction conn $ do+            _durationS <- apply script conn+            pure ()