diff --git a/persistent/ChangeLog.md b/persistent/ChangeLog.md index a61d83855..d7abec605 100644 --- a/persistent/ChangeLog.md +++ b/persistent/ChangeLog.md @@ -2,6 +2,13 @@ ## 2.14.0.0 (unreleased) +* [#1386](https://github.com/yesodweb/persistent/pull/1386) + * The module `Database.Persist.Class.DeleteCascade` was deleted since you + can put cascade behavior directly on your database models. + * Removed `mkSave` from `Database.Persist.TH`. Use `mkEntityDefList` + instead. + * Remove the `CompositeDef` constructor from `ReferenceDef` which was not + used internally anymore. * [#1384](https://github.com/yesodweb/persistent/pull/1384) * Add `tabulateEntityA` to the `PersistEntity` class, allowing you to construct an `Entity a` by providing a function `EntityField a t -> f t`. diff --git a/persistent/Database/Persist/Class.hs b/persistent/Database/Persist/Class.hs index f86855412..b58156bac 100644 --- a/persistent/Database/Persist/Class.hs +++ b/persistent/Database/Persist/Class.hs @@ -129,10 +129,6 @@ module Database.Persist.Class , selectSource , selectKeysList - -- * DeleteCascade - , DeleteCascade (..) - , deleteCascadeWhere - -- * PersistEntity , PersistEntity (..) , tabulateEntity @@ -164,7 +160,6 @@ module Database.Persist.Class , toPersistValueJSON, fromPersistValueJSON ) where -import Database.Persist.Class.DeleteCascade import Database.Persist.Class.PersistConfig import Database.Persist.Class.PersistEntity import Database.Persist.Class.PersistField diff --git a/persistent/Database/Persist/Class/DeleteCascade.hs b/persistent/Database/Persist/Class/DeleteCascade.hs deleted file mode 100644 index 4ab445994..000000000 --- a/persistent/Database/Persist/Class/DeleteCascade.hs +++ /dev/null @@ -1,39 +0,0 @@ -{-# LANGUAGE ExplicitForAll #-} - - -module Database.Persist.Class.DeleteCascade {-# DEPRECATED "The DeleteCascade module is deprecated. You can now set cascade behavior directly on entities in the quasiquoter." #-} - ( DeleteCascade (..) - , deleteCascadeWhere - ) where - -import Control.Monad.IO.Class (MonadIO, liftIO) -import Control.Monad.Reader (ReaderT, ask, runReaderT) -import Data.Conduit -import qualified Data.Conduit.List as CL -import Data.Acquire (with) - -import Database.Persist.Class.PersistStore -import Database.Persist.Class.PersistQuery -import Database.Persist.Class.PersistEntity - -{-# DEPRECATED DeleteCascade "The DeleteCascade class is deprecated since you can now define cascade behavior directly on an entity." #-} - --- | For combinations of backends and entities that support --- cascade-deletion. “Cascade-deletion” means that entries that depend on --- other entries to be deleted will be deleted as well. -class (PersistStoreWrite backend, PersistEntity record, BaseBackend backend ~ PersistEntityBackend record) - => DeleteCascade record backend where - - -- | Perform cascade-deletion of single database - -- entry. - deleteCascade :: MonadIO m => Key record -> ReaderT backend m () - -{-# DEPRECATED deleteCascadeWhere "This function is deprecated since you can set cascading delete behavior directly on the entity." #-} - --- | Cascade-deletion of entries satisfying given filters. -deleteCascadeWhere :: forall record backend m. (MonadIO m, DeleteCascade record backend, PersistQueryWrite backend) - => [Filter record] -> ReaderT backend m () -deleteCascadeWhere filts = do - srcRes <- selectKeysRes filts [] - conn <- ask - liftIO $ with srcRes (\src -> runConduit $ src .| CL.mapM_ (flip runReaderT conn . deleteCascade)) diff --git a/persistent/Database/Persist/SqlBackend/Internal.hs b/persistent/Database/Persist/SqlBackend/Internal.hs index ae7f58351..174754f8a 100644 --- a/persistent/Database/Persist/SqlBackend/Internal.hs +++ b/persistent/Database/Persist/SqlBackend/Internal.hs @@ -13,7 +13,6 @@ import Database.Persist.SqlBackend.Internal.InsertSqlResult import Database.Persist.SqlBackend.Internal.IsolationLevel import Database.Persist.SqlBackend.Internal.MkSqlBackend import Database.Persist.SqlBackend.Internal.Statement -import Database.Persist.SqlBackend.Internal.StatementCache (StatementCache) import Database.Persist.SqlBackend.StatementCache import Database.Persist.Types.Base diff --git a/persistent/Database/Persist/TH.hs b/persistent/Database/Persist/TH.hs index 9989eaa59..28fce71ab 100644 --- a/persistent/Database/Persist/TH.hs +++ b/persistent/Database/Persist/TH.hs @@ -49,8 +49,6 @@ module Database.Persist.TH , mkMigrate , migrateModels , discoverEntities - , mkSave - , mkDeleteCascade , mkEntityDefList , share , derivePersistField @@ -2302,24 +2300,10 @@ persistFieldFromEntity mps entDef = do -- -- This function is useful for cases such as: -- --- >>> share [mkSave "myDefs", mkPersist sqlSettings] [persistLowerCase|...|] +-- >>> share [mkEntityDefList "myDefs", mkPersist sqlSettings] [persistLowerCase|...|] share :: [[a] -> Q [Dec]] -> [a] -> Q [Dec] share fs x = mconcat <$> mapM ($ x) fs --- | Save the @EntityDef@s passed in under the given name. --- --- This function was deprecated in @persistent-2.13.0.0@. It doesn't properly --- fix foreign keys. Please refer to 'mkEntityDefList' for a replacement. -mkSave :: String -> [EntityDef] -> Q [Dec] -mkSave name' defs' = do - let name = mkName name' - defs <- lift defs' - return [ SigD name $ ListT `AppT` ConT ''EntityDef - , FunD name [normalClause [] defs] - ] - -{-# DEPRECATED mkSave "This function is broken. mkEntityDefList is a drop-in replacement that will properly handle foreign keys correctly." #-} - data Dep = Dep { depTarget :: EntityNameHS , depSourceTable :: EntityNameHS @@ -2327,73 +2311,6 @@ data Dep = Dep , depSourceNull :: IsNullable } -{-# DEPRECATED mkDeleteCascade "You can now set update and delete cascade behavior directly on the entity in the quasiquoter. This function and class are deprecated and will be removed in the next major ersion." #-} - --- | Generate a 'DeleteCascade' instance for the given @EntityDef@s. --- --- This function is deprecated as of 2.13.0.0. You can now set cascade --- behavior directly in the quasiquoter. -mkDeleteCascade :: MkPersistSettings -> [UnboundEntityDef] -> Q [Dec] -mkDeleteCascade mps defs = do - let deps = concatMap getDeps defs - mapM (go deps) defs - where - getDeps :: UnboundEntityDef -> [Dep] - getDeps def = - concatMap getDeps' $ getUnboundFieldDefs $ fixEntityDef def - where - getDeps' :: UnboundFieldDef -> [Dep] - getDeps' field = - case guessFieldReference field of - Just name -> - return Dep - { depTarget = name - , depSourceTable = entityHaskell (unboundEntityDef def) - , depSourceField = unboundFieldNameHS field - , depSourceNull = isUnboundFieldNullable field - } - Nothing -> - [] - go :: [Dep] -> UnboundEntityDef -> Q Dec - go allDeps ued = do - let name = entityHaskell (unboundEntityDef ued) - let deps = filter (\x -> depTarget x == name) allDeps - key <- newName "key" - let del = VarE 'delete - let dcw = VarE 'deleteCascadeWhere - just <- [|Just|] - filt <- [|Filter|] - eq <- [|Eq|] - value <- [|FilterValue|] - let mkStmt :: Dep -> Stmt - mkStmt dep = NoBindS - $ dcw `AppE` - ListE - [ filt `AppE` ConE filtName - `AppE` (value `AppE` val (depSourceNull dep)) - `AppE` eq - ] - where - filtName = filterConName' mps (depSourceTable dep) (depSourceField dep) - val (Nullable ByMaybeAttr) = just `AppE` VarE key - val _ = VarE key - - let stmts :: [Stmt] - stmts = fmap mkStmt deps `mappend` - [NoBindS $ del `AppE` VarE key] - - let entityT = genericDataType mps name backendT - - return $ - instanceD - [ mkClassP ''PersistQuery [backendT] - , mkEqualP (ConT ''PersistEntityBackend `AppT` entityT) (ConT ''BaseBackend `AppT` backendT) - ] - (ConT ''DeleteCascade `AppT` entityT `AppT` backendT) - [ FunD 'deleteCascade - [normalClause [VarP key] (mkDoE stmts)] - ] - -- | Creates a declaration for the @['EntityDef']@ from the @persistent@ -- schema. This is necessary because the Persistent QuasiQuoter is unable -- to know the correct type of ID fields, and assumes that they are all diff --git a/persistent/Database/Persist/Types/Base.hs b/persistent/Database/Persist/Types/Base.hs index 3accc4a31..89e675240 100644 --- a/persistent/Database/Persist/Types/Base.hs +++ b/persistent/Database/Persist/Types/Base.hs @@ -429,7 +429,6 @@ data ReferenceDef -- ^ A ForeignRef has a late binding to the EntityDef it references via name -- and has the Haskell type of the foreign key in the form of FieldType | EmbedRef EntityNameHS - | CompositeRef CompositeDef | SelfReference -- ^ A SelfReference stops an immediate cycle which causes non-termination at compile-time (issue #311). deriving (Show, Eq, Read, Ord, Lift) diff --git a/persistent/persistent.cabal b/persistent/persistent.cabal index 1f9cd4aed..2c8ebc3fe 100644 --- a/persistent/persistent.cabal +++ b/persistent/persistent.cabal @@ -84,7 +84,6 @@ library Database.Persist.SqlBackend.Internal.MkSqlBackend Database.Persist.Class - Database.Persist.Class.DeleteCascade Database.Persist.Class.PersistEntity Database.Persist.Class.PersistQuery Database.Persist.Class.PersistUnique