Skip to content

Commit

Permalink
Add keyAndEntityFieldsDatabase function to return key with migration …
Browse files Browse the repository at this point in the history
…only fields
  • Loading branch information
josephsumabat committed Sep 30, 2023
1 parent ad5585f commit 9976570
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions persistent/Database/Persist/Types/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,28 @@ entityKeyFields =
-- columns for an 'EntityDef'.
keyAndEntityFields :: EntityDef -> NonEmpty FieldDef
keyAndEntityFields ent =
case entityId ent of
keyWithFields (entityId ent) fields
where
fields = entityFields ent

-- | Returns a 'NonEmpty' list of 'FieldDef' that correspond with the key
-- columns for an 'EntityDef' including those fields that are marked as
-- 'MigrationOnly' (and therefore only present in the database) or
-- 'SafeToRemove' (and a migration will drop the column if it exists in the
-- database).
--
-- For fields on the Haskell type use 'keyAndEntityFieldsDatabase'
--
-- @since 2.14.7.0
keyAndEntityFieldsDatabase :: EntityDef -> NonEmpty FieldDef
keyAndEntityFieldsDatabase ent =
keyWithFields (entityId ent) fields
where
fields = filter isHaskellField $ entityFields ent

keyWithFields :: EntityIdDef -> [FieldDef] -> NonEmpty FieldDef
keyWithFields entId fields =
case entId of
EntityIdField fd ->
fd :| fields
EntityIdNaturalKey _ ->
Expand All @@ -214,8 +235,6 @@ keyAndEntityFields ent =
]
Just xs ->
xs
where
fields = filter isHaskellField $ entityFields ent

type ExtraLine = [Text]

Expand Down

0 comments on commit 9976570

Please sign in to comment.