packages feed

persistent-postgresql 2.11.0.0 → 2.11.0.1

raw patch · 3 files changed

+27/−5 lines, 3 files

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # Changelog for persistent-postgresql +##  2.11.0.1+* Fix foreign key migrations [#1167] https://github.com/yesodweb/persistent/pull/1167+  * Fix a bug where a foreign key of a field to its table was ignored.+  * Fix a bug where a altering details of a foreign key didn't trigger a migration+ ##  2.11.0.0  * Foreign Key improvements [#1121] https://github.com/yesodweb/persistent/pull/1121
Database/Persist/Postgresql.hs view
@@ -1237,8 +1237,7 @@                 refAdd (Just colRef) =                     case find ((== crTableName colRef) . entityDB) defs of                         Just refdef-                            | entityDB edef /= crTableName colRef-                            && _oldName /= fieldDB (entityId edef)+                            | _oldName /= fieldDB (entityId edef)                             ->                             [ ( crTableName colRef                               , AddReference@@ -1253,7 +1252,7 @@                             error $ "could not find the entityDef for reftable["                                 ++ show (crTableName colRef) ++ "]"                 modRef =-                    if fmap crConstraintName ref == fmap crConstraintName ref'+                    if equivalentRef ref ref'                         then []                         else refDrop ref' ++ refAdd ref                 modNull = case (isNull, isNull') of@@ -1291,6 +1290,24 @@                 , filter (\c -> cName c /= name) cols                 ) +-- We check if we should alter a foreign key. This is almost an equality check,+-- except we consider 'Nothing' and 'Just Restrict' equivalent.+equivalentRef :: Maybe ColumnReference -> Maybe ColumnReference -> Bool+equivalentRef Nothing Nothing = True+equivalentRef (Just cr1) (Just cr2) =+       crTableName cr1 == crTableName cr2+    && crConstraintName cr1 == crConstraintName cr2+    && eqCascade (fcOnUpdate $ crFieldCascade cr1) (fcOnUpdate $ crFieldCascade cr2)+    && eqCascade (fcOnDelete $ crFieldCascade cr1) (fcOnDelete $ crFieldCascade cr2)+  where+    eqCascade :: Maybe CascadeAction -> Maybe CascadeAction -> Bool+    eqCascade Nothing Nothing         = True+    eqCascade Nothing (Just Restrict) = True+    eqCascade (Just Restrict) Nothing = True+    eqCascade (Just cs1) (Just cs2)   = cs1 == cs2+    eqCascade _ _                     = False+equivalentRef _ _ = False+ -- | Get the references to be added to a table for the given column. getAddReference     :: [EntityDef]@@ -1299,7 +1316,7 @@     -> ColumnReference     -> Maybe AlterDB getAddReference allDefs entity cname cr@ColumnReference {crTableName = s, crConstraintName=constraintName} = do-    guard $ table /= s && cname /= fieldDB (entityId entity)+    guard $ cname /= fieldDB (entityId entity)     pure $ AlterColumn         table         ( s
persistent-postgresql.cabal view
@@ -1,5 +1,5 @@ name:            persistent-postgresql-version:         2.11.0.0+version:         2.11.0.1 license:         MIT license-file:    LICENSE author:          Felipe Lessa, Michael Snoyman <michael@snoyman.com>