yesodweb / yesodweb/persistent

Foreign key constraint name is weird

Open
#1,124 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue
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 Persistent 2.10.5.2 and Persistent Template 2.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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.