yesodweb / yesodweb/persistent
Non-default Id columns are a source of trouble
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
Suppose you write:
User
Id Text
name Text
age Int
This generates t able:
CREATE TABLE user (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
age INT NOT NULL
);
This will throw runtime errors whenever you try to insert a value with insert - we generate the following code from a insert User { userName = "foo", userAge = 40 } call:
INSERT INTO user (name, age) VALUES ("foo", 40);
But the user table has an id column - that is NOT NULL - with no default!
Approaches:
- Make
insertsafe with a class member like theOnlyOneUniqueinstance. Kind of ugly. - Error out on
Id Textwithout defaults while parsing the code. Maybe allow folks to use!forceto skip it. Maybe make this an optional thing - a value onPersistSettings.
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 by reproducing the generated INSERT for an entity with Id Text and no default, then trace how that schema and insert are produced. Review the proposed OnlyOneUnique and PersistSettings directions; the issue is done when the behavior for non-default, non-defaulted IDs is decided and the resulting insert or parse-time handling no longer fails at runtime.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100