Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package ghc-persistent for openSUSE:Factory checked in at 2023-04-04 21:22:21 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-persistent (Old) and /work/SRC/openSUSE:Factory/.ghc-persistent.new.19717 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "ghc-persistent" Tue Apr 4 21:22:21 2023 rev:37 rq:1075993 version:2.14.5.0 Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-persistent/ghc-persistent.changes 2023-01-18 13:10:37.560755243 +0100 +++ /work/SRC/openSUSE:Factory/.ghc-persistent.new.19717/ghc-persistent.changes 2023-04-04 21:22:31.433911688 +0200 @@ -1,0 +2,14 @@ +Thu Mar 30 17:07:52 UTC 2023 - Peter Simons <psim...@suse.com> + +- Updated spec file to conform with ghc-rpm-macros-2.5.2. + +------------------------------------------------------------------- +Sat Mar 4 19:05:21 UTC 2023 - Peter Simons <psim...@suse.com> + +- Update persistent to version 2.14.5.0. + Upstream has edited the change log file since the last release in + a non-trivial way, i.e. they did more than just add a new entry + at the top. You can review the file at: + http://hackage.haskell.org/package/persistent-2.14.5.0/src/ChangeLog.md + +------------------------------------------------------------------- Old: ---- persistent-2.14.4.4.tar.gz New: ---- persistent-2.14.5.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-persistent.spec ++++++ --- /var/tmp/diff_new_pack.tdaXJN/_old 2023-04-04 21:22:32.057915222 +0200 +++ /var/tmp/diff_new_pack.tdaXJN/_new 2023-04-04 21:22:32.065915267 +0200 @@ -17,9 +17,10 @@ %global pkg_name persistent +%global pkgver %{pkg_name}-%{version} %bcond_with tests Name: ghc-%{pkg_name} -Version: 2.14.4.4 +Version: 2.14.5.0 Release: 0 Summary: Type-safe, multi-backend data serialization License: MIT @@ -27,40 +28,74 @@ Source0: https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz BuildRequires: ghc-Cabal-devel BuildRequires: ghc-aeson-devel +BuildRequires: ghc-aeson-prof BuildRequires: ghc-attoparsec-devel +BuildRequires: ghc-attoparsec-prof +BuildRequires: ghc-base-devel +BuildRequires: ghc-base-prof BuildRequires: ghc-base64-bytestring-devel +BuildRequires: ghc-base64-bytestring-prof BuildRequires: ghc-blaze-html-devel +BuildRequires: ghc-blaze-html-prof BuildRequires: ghc-bytestring-devel +BuildRequires: ghc-bytestring-prof BuildRequires: ghc-conduit-devel +BuildRequires: ghc-conduit-prof BuildRequires: ghc-containers-devel +BuildRequires: ghc-containers-prof BuildRequires: ghc-deepseq-devel +BuildRequires: ghc-deepseq-prof BuildRequires: ghc-fast-logger-devel +BuildRequires: ghc-fast-logger-prof BuildRequires: ghc-http-api-data-devel +BuildRequires: ghc-http-api-data-prof BuildRequires: ghc-lift-type-devel +BuildRequires: ghc-lift-type-prof BuildRequires: ghc-monad-logger-devel +BuildRequires: ghc-monad-logger-prof BuildRequires: ghc-mtl-devel +BuildRequires: ghc-mtl-prof BuildRequires: ghc-path-pieces-devel +BuildRequires: ghc-path-pieces-prof BuildRequires: ghc-resource-pool-devel +BuildRequires: ghc-resource-pool-prof BuildRequires: ghc-resourcet-devel +BuildRequires: ghc-resourcet-prof BuildRequires: ghc-rpm-macros BuildRequires: ghc-scientific-devel +BuildRequires: ghc-scientific-prof BuildRequires: ghc-silently-devel +BuildRequires: ghc-silently-prof BuildRequires: ghc-template-haskell-devel +BuildRequires: ghc-template-haskell-prof BuildRequires: ghc-text-devel +BuildRequires: ghc-text-prof BuildRequires: ghc-th-lift-instances-devel +BuildRequires: ghc-th-lift-instances-prof BuildRequires: ghc-time-devel +BuildRequires: ghc-time-prof BuildRequires: ghc-transformers-devel +BuildRequires: ghc-transformers-prof BuildRequires: ghc-unliftio-core-devel +BuildRequires: ghc-unliftio-core-prof BuildRequires: ghc-unliftio-devel +BuildRequires: ghc-unliftio-prof BuildRequires: ghc-unordered-containers-devel +BuildRequires: ghc-unordered-containers-prof BuildRequires: ghc-vault-devel +BuildRequires: ghc-vault-prof BuildRequires: ghc-vector-devel +BuildRequires: ghc-vector-prof ExcludeArch: %{ix86} %if %{with tests} BuildRequires: ghc-QuickCheck-devel +BuildRequires: ghc-QuickCheck-prof BuildRequires: ghc-hspec-devel +BuildRequires: ghc-hspec-prof BuildRequires: ghc-quickcheck-instances-devel +BuildRequires: ghc-quickcheck-instances-prof BuildRequires: ghc-shakespeare-devel +BuildRequires: ghc-shakespeare-prof %endif %description @@ -77,6 +112,22 @@ %description devel This package provides the Haskell %{pkg_name} library development files. +%package -n ghc-%{pkg_name}-doc +Summary: Haskell %{pkg_name} library documentation +Requires: ghc-filesystem +BuildArch: noarch + +%description -n ghc-%{pkg_name}-doc +This package provides the Haskell %{pkg_name} library documentation. + +%package -n ghc-%{pkg_name}-prof +Summary: Haskell %{pkg_name} profiling library +Requires: ghc-%{pkg_name}-devel = %{version}-%{release} +Supplements: (ghc-%{pkg_name}-devel and ghc-prof) + +%description -n ghc-%{pkg_name}-prof +This package provides the Haskell %{pkg_name} profiling library. + %prep %autosetup -n %{pkg_name}-%{version} @@ -101,4 +152,9 @@ %files devel -f %{name}-devel.files %doc ChangeLog.md README.md +%files -n ghc-%{pkg_name}-doc -f ghc-%{pkg_name}-doc.files +%license LICENSE + +%files -n ghc-%{pkg_name}-prof -f ghc-%{pkg_name}-prof.files + %changelog ++++++ persistent-2.14.4.4.tar.gz -> persistent-2.14.5.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/persistent-2.14.4.4/ChangeLog.md new/persistent-2.14.5.0/ChangeLog.md --- old/persistent-2.14.4.4/ChangeLog.md 2023-01-05 17:07:30.000000000 +0100 +++ new/persistent-2.14.5.0/ChangeLog.md 2023-03-04 20:05:05.000000000 +0100 @@ -1,8 +1,24 @@ # Changelog for persistent +## 2.14.5.0 + +* [#1469](https://github.com/yesodweb/persistent/pull/1469) + * Change default implementation for `insertUnique_` to not perform + unecessary queries (mirrors 1449) +* [#1437](https://github.com/yesodweb/persistent/pull/1437) + * Add `existsBy` to `PersistUniqueRead` + +## 2.14.4.5 + +* [#1460](https://github.com/yesodweb/persistent/pull/1468) + * Remove extraneous `map toPersistValue` call in the `mkInsertValues` + function, as it evaluates to `id`. +* [#1476](https://github.com/yesodweb/persistent/pull/1476) + * Fix `mkRecordName` to suffix `_` if the field name matches any of Haskell keywords. + ## 2.14.4.4 -* [#1460] https://github.com/yesodweb/persistent/pull/1460 +* [#1460](https://github.com/yesodweb/persistent/pull/1460) * Fix a problem where a `Primary` key causes `mkPersist` to generate code that doesn't compile under `NoFieldSelectors` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/persistent-2.14.4.4/Database/Persist/Class/PersistUnique.hs new/persistent-2.14.5.0/Database/Persist/Class/PersistUnique.hs --- old/persistent-2.14.4.4/Database/Persist/Class/PersistUnique.hs 2022-10-19 22:24:56.000000000 +0200 +++ new/persistent-2.14.5.0/Database/Persist/Class/PersistUnique.hs 2023-03-04 20:04:44.000000000 +0100 @@ -33,7 +33,7 @@ import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.List.NonEmpty as NEL import qualified Data.Map as Map -import Data.Maybe (catMaybes) +import Data.Maybe (catMaybes, isJust) import GHC.TypeLits (ErrorMessage(..)) import Database.Persist.Class.PersistEntity @@ -78,6 +78,26 @@ :: forall record m. (MonadIO m, PersistRecordBackend record backend) => Unique record -> ReaderT backend m (Maybe (Entity record)) + -- | Returns True if a record with this unique key exists, otherwise False. + -- + -- === __Example usage__ + -- + -- With <#schema-persist-unique-1 schema-1> and <#dataset-persist-unique-1 dataset-1>: + -- + -- > existsBySpjName :: MonadIO m => ReaderT SqlBackend m Bool + -- > existsBySpjName = existsBy $ UniqueUserName "SPJ" + -- + -- > spjEntExists <- existsBySpjName + -- + -- The above query when applied on <#dataset-persist-unique-1 dataset-1>, will return + -- the value True. + -- + -- @since 2.14.5 + existsBy + :: forall record m. (MonadIO m, PersistRecordBackend record backend) + => Unique record -> ReaderT backend m Bool + existsBy uniq = isJust <$> getBy uniq + -- | Some functions in this module ('insertUnique', 'insertBy', and -- 'replaceUnique') first query the unique indexes to check for -- conflicts. You could instead optimistically attempt to perform the @@ -140,6 +160,37 @@ Nothing -> Just `liftM` insert datum Just _ -> return Nothing + -- | Same as 'insertUnique' but doesn't return a @Key@. + -- + -- === __Example usage__ + -- + -- With <#schema-persist-unique-1 schema-1> and <#dataset-persist-unique-1 dataset-1>, we try to insert the following two records: + -- + -- > linusId <- insertUnique_ $ User "Linus" 48 + -- > spjId <- insertUnique_ $ User "SPJ" 90 + -- + -- > +-----+------+-----+ + -- > |id |name |age | + -- > +-----+------+-----+ + -- > |1 |SPJ |40 | + -- > +-----+------+-----+ + -- > |2 |Simon |41 | + -- > +-----+------+-----+ + -- > |3 |Linus |48 | + -- > +-----+------+-----+ + -- + -- Linus's record was inserted to <#dataset-persist-unique-1 dataset-1>, while SPJ wasn't because SPJ already exists in <#dataset-persist-unique-1 dataset-1>. + -- + -- @since 2.14.5.0 + insertUnique_ + :: forall record m. (MonadIO m, PersistRecordBackend record backend, SafeToInsert record) + => record -> ReaderT backend m (Maybe ()) + insertUnique_ datum = do + conflict <- checkUnique datum + case conflict of + Nothing -> Just `liftM` insert_ datum + Just _ -> return Nothing + -- | Update based on a uniqueness constraint or insert: -- -- * insert the new record if it does not exist; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/persistent-2.14.4.4/Database/Persist/Compatible/Types.hs new/persistent-2.14.5.0/Database/Persist/Compatible/Types.hs --- old/persistent-2.14.4.4/Database/Persist/Compatible/Types.hs 2022-10-17 21:15:14.000000000 +0200 +++ new/persistent-2.14.5.0/Database/Persist/Compatible/Types.hs 2023-03-04 20:04:44.000000000 +0100 @@ -12,10 +12,10 @@ ( Compatible(..) ) where +import Control.Monad.Trans.Reader (withReaderT) import Data.Aeson import Database.Persist.Class import Database.Persist.Sql.Class -import Control.Monad.Trans.Reader (withReaderT) -- | A newtype wrapper for compatible backends, mainly useful for @DerivingVia@. @@ -104,6 +104,7 @@ instance (HasPersistBackend b, BackendCompatible b s, PersistUniqueRead b) => PersistUniqueRead (Compatible b s) where getBy = withReaderT (projectBackend @b @s . unCompatible) . getBy + existsBy = withReaderT (projectBackend @b @s . unCompatible) . existsBy instance (HasPersistBackend b, BackendCompatible b s, PersistStoreWrite b) => PersistStoreWrite (Compatible b s) where insert = withReaderT (projectBackend @b @s . unCompatible) . insert diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/persistent-2.14.4.4/Database/Persist/Sql/Orphan/PersistQuery.hs new/persistent-2.14.5.0/Database/Persist/Sql/Orphan/PersistQuery.hs --- old/persistent-2.14.4.4/Database/Persist/Sql/Orphan/PersistQuery.hs 2022-10-17 21:15:14.000000000 +0200 +++ new/persistent-2.14.5.0/Database/Persist/Sql/Orphan/PersistQuery.hs 2023-03-04 20:04:44.000000000 +0100 @@ -41,6 +41,7 @@ , keyAndEntityColumnNames , mkUpdateText , parseEntityValues + , parseExistsResult , updatePersistValue ) @@ -82,15 +83,7 @@ ] withRawQuery sql (getFiltsValues conn filts) $ do mm <- CL.head - case mm of - Just [PersistBool b] -> return b -- Postgres - Just [PersistInt64 i] -> return $ i > 0 -- MySQL, SQLite - Just [PersistDouble i] -> return $ (truncate i :: Int64) > 0 -- gb oracle - Just [PersistByteString i] -> case readInteger i of -- gb mssql - Just (ret,"") -> return $ ret > 0 - xs -> error $ "invalid number i["++show i++"] xs[" ++ show xs ++ "]" - Just xs -> error $ "PersistQuery.exists: Expected a boolean, int, double, or bytestring; got: " ++ show xs ++ " for query: " ++ show sql - Nothing -> error $ "PersistQuery.exists: Expected a boolean, int, double, or bytestring; got: Nothing for query: " ++ show sql + return $ parseExistsResult mm sql "PersistQuery.exists" where t = entityDef $ dummyFromFilts filts diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/persistent-2.14.4.4/Database/Persist/Sql/Orphan/PersistUnique.hs new/persistent-2.14.5.0/Database/Persist/Sql/Orphan/PersistUnique.hs --- old/persistent-2.14.4.4/Database/Persist/Sql/Orphan/PersistUnique.hs 2022-10-17 21:15:14.000000000 +0200 +++ new/persistent-2.14.5.0/Database/Persist/Sql/Orphan/PersistUnique.hs 2023-03-04 20:04:44.000000000 +0100 @@ -1,4 +1,4 @@ -{-# LANGUAGE ExplicitForAll #-} +{-# LANGUAGE ExplicitForAll #-} {-# OPTIONS_GHC -fno-warn-orphans #-} module Database.Persist.Sql.Orphan.PersistUnique () @@ -8,18 +8,25 @@ import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans.Reader (ask) import qualified Data.Conduit.List as CL +import Data.Foldable (toList) import Data.Function (on) import Data.List (nubBy) import qualified Data.Text as T -import Data.Foldable (toList) import Database.Persist -import Database.Persist.Class.PersistUnique (defaultUpsertBy, defaultPutMany, persistUniqueKeyValues) +import Database.Persist.Class.PersistUnique + (defaultPutMany, defaultUpsertBy, persistUniqueKeyValues) -import Database.Persist.Sql.Types.Internal -import Database.Persist.Sql.Raw import Database.Persist.Sql.Orphan.PersistStore (withRawQuery) -import Database.Persist.Sql.Util (dbColumns, parseEntityValues, updatePersistValue, mkUpdateText') +import Database.Persist.Sql.Raw +import Database.Persist.Sql.Types.Internal +import Database.Persist.Sql.Util + ( dbColumns + , mkUpdateText' + , parseEntityValues + , parseExistsResult + , updatePersistValue + ) instance PersistUniqueWrite SqlBackend where upsertBy uniqueKey record updates = do @@ -110,11 +117,34 @@ t = entityDef $ dummyFromUnique uniq toFieldNames' = toList . fmap snd . persistUniqueToFieldNames + existsBy uniq = do + conn <- ask + let sql = + T.concat + [ "SELECT EXISTS(SELECT 1 FROM " + , connEscapeTableName conn t + , " WHERE " + , sqlClause conn + , ")" + ] + uvals = persistUniqueToValues uniq + withRawQuery sql uvals $ do + mm <- CL.head + return $ parseExistsResult mm sql "PersistUnique.existsBy" + where + sqlClause conn = + T.intercalate " AND " $ map (go conn) $ toFieldNames' uniq + go conn x = connEscapeFieldName conn x `mappend` "=?" + t = entityDef $ dummyFromUnique uniq + toFieldNames' = toList . fmap snd . persistUniqueToFieldNames + instance PersistUniqueRead SqlReadBackend where getBy uniq = withBaseBackend $ getBy uniq + existsBy uniq = withBaseBackend $ existsBy uniq instance PersistUniqueRead SqlWriteBackend where getBy uniq = withBaseBackend $ getBy uniq + existsBy uniq = withBaseBackend $ existsBy uniq dummyFromUnique :: Unique v -> Maybe v dummyFromUnique _ = Nothing diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/persistent-2.14.4.4/Database/Persist/Sql/Util.hs new/persistent-2.14.5.0/Database/Persist/Sql/Util.hs --- old/persistent-2.14.4.4/Database/Persist/Sql/Util.hs 2022-10-17 21:15:14.000000000 +0200 +++ new/persistent-2.14.5.0/Database/Persist/Sql/Util.hs 2023-03-04 20:04:44.000000000 +0100 @@ -18,8 +18,11 @@ , parenWrapped , mkInsertValues , mkInsertPlaceholders + , parseExistsResult ) where +import Data.ByteString.Char8 (readInteger) +import Data.Int (Int64) import Data.List.NonEmpty (NonEmpty(..)) import qualified Data.Maybe as Maybe import Data.Text (Text, pack) @@ -34,7 +37,7 @@ , FieldNameHS(FieldNameHS) , PersistEntity(..) , PersistUpdate(..) - , PersistValue + , PersistValue(..) , Update(..) , compositeFields , entityPrimary @@ -243,7 +246,6 @@ mkInsertValues entity = Maybe.catMaybes . zipWith redactGeneratedCol (getEntityFields . entityDef $ Just entity) - . map toPersistValue $ toPersistFields entity where redactGeneratedCol fd pv = case fieldGenerated fd of @@ -271,3 +273,15 @@ Just (escape (fieldDB fd), "?") Just _ -> Nothing + +parseExistsResult :: Maybe [PersistValue] -> Text -> String -> Bool +parseExistsResult mm sql errloc = + case mm of + Just [PersistBool b] -> b -- Postgres + Just [PersistInt64 i] -> i > 0 -- MySQL, SQLite + Just [PersistDouble i] -> (truncate i :: Int64) > 0 -- gb oracle + Just [PersistByteString i] -> case readInteger i of -- gb mssql + Just (ret,"") -> ret > 0 + xs -> error $ "invalid number i["++show i++"] xs[" ++ show xs ++ "]" + Just xs -> error $ errloc ++ ": Expected a boolean, int, double, or bytestring; got: " ++ show xs ++ " for query: " ++ show sql + Nothing -> error $ errloc ++ ": Expected a boolean, int, double, or bytestring; got: Nothing for query: " ++ show sql diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/persistent-2.14.4.4/Database/Persist/TH.hs new/persistent-2.14.5.0/Database/Persist/TH.hs --- old/persistent-2.14.4.4/Database/Persist/TH.hs 2023-01-05 17:07:30.000000000 +0100 +++ new/persistent-2.14.5.0/Database/Persist/TH.hs 2023-03-03 17:55:42.000000000 +0100 @@ -3100,7 +3100,7 @@ mkRecordName :: MkPersistSettings -> Maybe Text -> EntityNameHS -> FieldNameHS -> Name mkRecordName mps prefix entNameHS fieldNameHS = - mkName $ T.unpack $ fromMaybe "" prefix <> lowerFirst recName + mkName $ T.unpack . avoidKeyword $ fromMaybe "" prefix <> lowerFirst recName where recName :: Text recName @@ -3115,6 +3115,17 @@ fieldNameText = unFieldNameHS fieldNameHS + avoidKeyword :: Text -> Text + avoidKeyword name = if name `Set.member` haskellKeywords then name ++ "_" else name + +haskellKeywords :: Set.Set Text +haskellKeywords = Set.fromList + ["case","class","data","default","deriving","do","else" + ,"if","import","in","infix","infixl","infixr","instance","let","module" + ,"newtype","of","then","type","where","_" + ,"foreign" + ] + -- | Construct a list of TH Names for the typeclasses of an EntityDef's `entityDerives` mkEntityDefDeriveNames :: MkPersistSettings -> UnboundEntityDef -> [Name] mkEntityDefDeriveNames mps entDef = diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/persistent-2.14.4.4/persistent.cabal new/persistent-2.14.5.0/persistent.cabal --- old/persistent-2.14.4.4/persistent.cabal 2023-01-05 17:07:30.000000000 +0100 +++ new/persistent-2.14.5.0/persistent.cabal 2023-03-04 20:04:44.000000000 +0100 @@ -1,5 +1,5 @@ name: persistent -version: 2.14.4.4 +version: 2.14.5.0 license: MIT license-file: LICENSE author: Michael Snoyman <mich...@snoyman.com> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/persistent-2.14.4.4/test/Database/Persist/TH/NoFieldSelectorsSpec.hs new/persistent-2.14.5.0/test/Database/Persist/TH/NoFieldSelectorsSpec.hs --- old/persistent-2.14.4.4/test/Database/Persist/TH/NoFieldSelectorsSpec.hs 2023-01-05 17:07:30.000000000 +0100 +++ new/persistent-2.14.5.0/test/Database/Persist/TH/NoFieldSelectorsSpec.hs 2023-03-03 17:55:42.000000000 +0100 @@ -25,6 +25,7 @@ name Text Primary ident team TeamId + type Text Team name Text