yesodweb / yesodweb/persistent

newtype interferes with unique constraints in MySQL

Open
#100 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Request good first issue MySQL
Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

Text fields can have unique constraints over them.

However, when a Text field is newtype'd, for extra type safety, this facility appears to break:

In Model.hs with GeneralizedNewtypeDeriving:

newtype Hash = Hash { unHash :: Text }
    deriving (Show, Read, Eq, PathPiece, PersistField)

In config/models:

Profile
  hash Hash
  UniqueHash hash

On initial database migration with mysql, we see:

Migrating: ALTER TABLE `profile` ADD CONSTRAINT `unique_hash` UNIQUE(`hash`)
hpd3js: ConnectionError {errFunction = "query", errNumber = 1170, errMessage = "BLOB/TEXT column 'hash' used in key specification without a key length"}

Uncaught instance of overlapping instances floating around, perhaps? (Am I missing a deriving statement?)

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 with the newtype and deriving declarations in Model.hs, the Profile schema in config/models, and the initial MySQL migration shown in the report. Reproduce the migration and trace how PersistField types become MySQL unique-key definitions; done means the newtype-wrapped Text field can be migrated with its unique constraint without the key-length error.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.