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
2 changes: 2 additions & 0 deletions persistent/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 2.13.0.0 (unreleased)

* [#1244](https://github.com/yesodweb/persistent/pull/1244)
* Implement config for customising the FK name
* [#1252](https://github.com/yesodweb/persistent/pull/1252)
* `mkMigrate` now defers to `mkEntityDefList` and `migrateModels` instead of
fixing the foreign key references itself.
Expand Down
16 changes: 16 additions & 0 deletions persistent/Database/Persist/Quasi.hs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ module Database.Persist.Quasi
) where

import Data.Text (Text)
import Database.Persist.Names
import Database.Persist.Quasi.Internal

-- | Retrieve the function in the 'PersistSettings' that modifies the names into
Expand All @@ -439,6 +440,21 @@ getPsToDBName = psToDBName
setPsToDBName :: (Text -> Text) -> PersistSettings -> PersistSettings
setPsToDBName f ps = ps { psToDBName = f }

-- | Set a custom function used to create the constraint name
-- for a foreign key.
--
-- @since 2.13.0.0
setPsToFKName :: (EntityNameHS -> ConstraintNameHS -> Text) -> PersistSettings -> PersistSettings
setPsToFKName setter ps = ps { psToFKName = setter }
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful 👍🏻


-- | A preset configuration function that puts an underscore
-- between the entity name and the constraint name when
-- creating a foreign key constraint name
--
-- @since 2.13.0.0
setPsUseSnakeCaseForiegnKeys :: PersistSettings -> PersistSettings
setPsUseSnakeCaseForiegnKeys = setPsToFKName (toFKNameInfixed "_")

-- | Retrieve whether or not the 'PersistSettings' will generate code with
-- strict fields.
--
Expand Down
Loading