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
7 changes: 7 additions & 0 deletions persistent/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
5 changes: 0 additions & 5 deletions persistent/Database/Persist/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ module Database.Persist.Class
, selectSource
, selectKeysList

-- * DeleteCascade
, DeleteCascade (..)
, deleteCascadeWhere

-- * PersistEntity
, PersistEntity (..)
, tabulateEntity
Expand Down Expand Up @@ -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
Expand Down
39 changes: 0 additions & 39 deletions persistent/Database/Persist/Class/DeleteCascade.hs

This file was deleted.

1 change: 0 additions & 1 deletion persistent/Database/Persist/SqlBackend/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
85 changes: 1 addition & 84 deletions persistent/Database/Persist/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ module Database.Persist.TH
, mkMigrate
, migrateModels
, discoverEntities
, mkSave
, mkDeleteCascade
, mkEntityDefList
, share
, derivePersistField
Expand Down Expand Up @@ -2302,98 +2300,17 @@ 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
, depSourceField :: FieldNameHS
, 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
Expand Down
1 change: 0 additions & 1 deletion persistent/Database/Persist/Types/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion persistent/persistent.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down