yesodweb / yesodweb/persistent

Non-default Id columns are a source of trouble

Open
#1,247 1 comment 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

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:

  1. Make insert safe with a class member like the OnlyOneUnique instance. Kind of ugly.
  2. Error out on Id Text without defaults while parsing the code. Maybe allow folks to use !force to skip it. Maybe make this an optional thing - a value on PersistSettings.

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.