yesodweb / yesodweb/persistent
Foreign key constraint name is weird
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I am unsure if this is intentional - in which case this is a request for improvement - or not - in which case this is a bug report.
The foreign key constraint name is weird: it seems that the (mandatory) constraint name passed in the quasi quoter is appended with no separator (e.g. _) to the FK table name.
FYI I use:
- Stack with resolver
lts-16.5, so Persistent2.10.5.2and Persistent Template2.8.2.3 - PostgreSQL
11.8
To reproduce:
share
[mkPersist sqlSettings, mkMigrate "migrateAll"]
[persistLowerCase|
FooBar
foo String
bar Bool
Primary foo bar
deriving Show
FooBarBaz
foo String
bar Bool
baz Int
Primary foo bar baz
Foreign FooBar fk_something foo bar
deriving Show
|]
The foreign key constraint is named foo_bar_bazfk_something, i.e. it appends the table name foo_bar_baz to the provided QQ name fk_something with no separator.
While I don't mind being forced to prefix with the table name foo_bar_baz, I don't understand why there isn't at least a separator _ between the table name and the given suffix (so it would be foo_bar_baz_fk_something). And it's illegal (doesn't compile) to write Foreign FooBar _fk_something foo bar.
What do you think?
Cheers!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided persistLowerCase definition and mkPersist sqlSettings entry points, then inspect how the Foreign declaration becomes a PostgreSQL constraint name. Reproduce the generated name with the example and PostgreSQL 11.8; done means the constraint naming behavior matches the requested separator convention or is clearly documented as intentional.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell, postgresql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100