luckyframework / luckyframework/avram

Unclear error when using add_index with column which already has an index

Open
#117 0 comments 0 reactions 0 assignees View on GitHub
documentation improve error experience
Dominant language
Crystal
Stars
183
Forks
67
PR merge metrics
No merged PRs in 30d

Description

Consider the following migration:

~~~crystal
class CreateTags::V20190623184241 < Avram::Migrator::Migration::V1
def migrate
create :tags do
add name : String, unique: true
end

add_index :name, unique: true
end

def rollback
drop :tags
end
end
~~~

The `unique: true` parameter to the `add` method automatically creates a unique index for that column. I didn't realize this initially, and adding the `add_index` statement below caused the migration to fail with a really unclear error:

https://gist.github.com/taylorthurlow/98bc7018ea9254ceb7e476ca87c368a3

I solved the issue by just removing the redundant `add_index` call. In the future it might be a better idea to fail with a descriptive error message.

Contributor guide

Open the contributing guide

Research direction

Start by tracing Avram's migration add_index path and the unique: true handling shown in the example; inspect the failing migration behavior from the linked gist. Done means attempting a duplicate index produces a descriptive error explaining that the column already has an index, with coverage for this migration case.

Written by the indexing model from the issue text.

Assessment

Tech stack
crystal, postgresql
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.