yesodweb / yesodweb/persistent
Declaring additional foreign key constraints
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
Currently foreign keys are only created via directly using a ###Id type in another column. However there are a variety of use cases that fit outside of this.
For example it is useful to have the primary key be a foreign key to the parent type, in order to implement table per class inheritance.
In general SQL allows foreign keys to go from any set of columns in one table to an equally typed set of columns in another table.
It would great to be able to declare these foreign keys in Persistent.
One interesting thing to consider if that in SQL both ends of a foreign key have to have identical types (uuid, int8 etc.). However in Persistent it would be useful to allow for a supertype foreign key, such as DogId(uuid) -> AnimalId(uuid). It would also be useful if those foreign keys came with an "upcast" instance to allow for easy and safe conversions.
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
The issue names no files, tests, or entry points. Start by locating the existing Persistent logic that creates foreign keys from ###Id columns, then review how schema declarations represent column types. Done would require a defined way to declare foreign keys between arbitrary column sets, with the proposed supertype and upcast behavior resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100