yesodweb / yesodweb/persistent

Self Reference foreign keys are not generated

Open
#1,169 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

A migration like this:

Chain
    previousChain ChainId Maybe
    deriving Show Eq

will fail to generate any foreign keys at postgreSQL. I have narrowed down the bug to the getAddReference function, at the guard guard $ table /= s && cname /= fieldDB (entityId entity), especially the first check. Removing that fixes the problem. I think the check was added for the sql=id option https://github.com/yesodweb/persistent/pull/1066, so simply removing it may break other stuff?

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 by locating the getAddReference function and inspect the guard involving table, cname, and fieldDB (entityId entity). Compare its behavior with the sql=id change discussed in pull request 1066, using the self-referencing Chain migration as the reproduction. Done means self-reference foreign keys are generated for PostgreSQL without regressing the sql=id behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.