yesodweb / yesodweb/persistent
MySQL insert is broken on non-auto incrementing primary keys
Nobody has claimed this yet.
- Dominant language
- Haskell
- Stars
- 486
- Forks
- 306
- PR merge metrics
- No merged PRs in 30d
Description
MySQL can't do RETURNING (tho Maria DB can), which means that our insert needs to pair it with a SELECT LAST_INSERT_ID().
Of course, LAST_INSERT_ID() only works with auto incrementing primary keys. It fails utterly with (as an example) the UUID type.
The general recommended fix is to write something like:
CREATE TABLE foo (
id VARCHAR(80) DEFAULT (UUID()) PRIMARY KEY,
name VARCUAR (80) NOT NULL
);
INSERT INTO foo (id, name) VALUES (@last_foo_id = UUID(), ?);
SELECT @last_foo_id;
which is, y'know, horrible.
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 or tests. Start by locating the MySQL insert implementation and its LAST_INSERT_ID handling, then reproduce the failure with a UUID or other non-auto-incrementing primary key. Done means inserts work for such keys without breaking auto-increment behavior, with regression coverage for both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell, mysql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100