Skip to content
Open
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
5 changes: 3 additions & 2 deletions persistent/Database/Persist/Quasi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,9 @@ AnotherVeryLongTableName
These options affects how a referring record behaves when the target record is changed.
There are several options:

* 'Restrict' - This is the default. It prevents the action from occurring.
* 'Cascade' - this copies the change to the child record. If a parent record is deleted, then the child record will be deleted too.
* 'NoAction' - This is the default since 2.15.0.0. It checks constraints at the end of the transaction, aborting it if a violation is found.
* 'Restrict' - This is the default prior to 2.15.0.0. It immediately checks constraints, aborting the transaction if a violation is found.
* 'Cascade' - This copies the change to the child record. If a parent record is deleted, then the child record will be deleted too.
* 'SetNull' - If the parent record is modified, then this sets the reference to @NULL@. This only works on @Maybe@ foreign keys.
* 'SetDefault' - This will set the column's value to the @default@ for the column, if specified.

Expand Down
6 changes: 3 additions & 3 deletions persistent/Database/Persist/Sql/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ mkColumns allDefs t overrides =
$ ref (fieldDB fd) (fieldReference fd) (fieldAttrs fd)

-- a 'Nothing' in the definition means that the QQ migration doesn't
-- specify behavior. the default is RESTRICT. setting this here
-- specify behavior. the default is NO ACTION. setting this here
-- explicitly makes migrations run smoother.
overrideNothings (FieldCascade { fcOnUpdate = upd, fcOnDelete = del }) =
FieldCascade
{ fcOnUpdate = upd <|> Just Restrict
, fcOnDelete = del <|> Just Restrict
{ fcOnUpdate = upd <|> Just NoAction
, fcOnDelete = del <|> Just NoAction
}

ref :: FieldNameDB
Expand Down
13 changes: 11 additions & 2 deletions persistent/Database/Persist/Types/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,10 @@ data ForeignDef = ForeignDef
-- This type is used in both parsing the model definitions and performing
-- migrations. A 'Nothing' in either of the field values means that the
-- user has not specified a 'CascadeAction'. An unspecified 'CascadeAction'
-- is defaulted to 'Restrict' when doing migrations.
-- is defaulted to:
--
-- * 'NoAction' in versions @>=2.15.0.0@
-- * 'Restrict' in versions @<2.15.0.0@
--
-- @since 2.11.0
data FieldCascade = FieldCascade
Expand Down Expand Up @@ -585,7 +588,12 @@ renderFieldCascade (FieldCascade onUpdate onDelete) =
-- change.
--
-- @since 2.11.0
data CascadeAction = Cascade | Restrict | SetNull | SetDefault
data CascadeAction
= Cascade
| NoAction -- ^ @since 2.15.0.0
| Restrict
| SetNull
| SetDefault
deriving (Show, Eq, Read, Ord, Lift)

-- | Render a 'CascadeAction' to 'Text' such that it can be used in a SQL
Expand All @@ -595,6 +603,7 @@ data CascadeAction = Cascade | Restrict | SetNull | SetDefault
renderCascadeAction :: CascadeAction -> Text
renderCascadeAction action = case action of
Cascade -> "CASCADE"
NoAction -> "NO ACTION"
Restrict -> "RESTRICT"
SetNull -> "SET NULL"
SetDefault -> "SET DEFAULT"
Expand Down