luckyframework / luckyframework/avram

Confusing error when running migrations with issues

Open
#256 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

improve error experience
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

If you have the following

```crystal
def migrate
create table_for(Comment) do
primary_key id : UUID
add_timestamps
add_belongs_to user : User, on_delete: :cascade
end
end
```

Then you run `lucky db.migrate`, you may run in to an error that mentions something like:
```
foreign key constraint "comment_user_id_fkey" cannot be implemented (Exception)
```

This is because the user id might be `UUID`, but you forgot to add the `foreign_key_type: UUID` to your `add_belongs_to`.

If we have a way to catch this error, we should.

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 at the migration path invoked by `lucky db.migrate` and inspect how `add_belongs_to` handles a UUID foreign key when `foreign_key_type` is omitted. Reproduce the example with `Comment` and `User`; done means the migration reports a clear, actionable error instead of the raw foreign-key constraint failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.