-
Notifications
You must be signed in to change notification settings - Fork 21.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
index option added for change_table migrations #23593
Conversation
(@rails-bot has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still relevant in Rails 6 (e925cb4). Approach looks good to me. Please rebase and fix the CHANGELOG conflict and we can look at getting this merged!
@rafaelfranca you were the one with objection on this feature, are you still against of this? If not, I'll resolve the conflicts and then we can merge. I remember too many times I tried to add columns to tables with indices by forgetting that rails does not support this feature and it's really annoying. WDYT? |
If there's still pushback, you could refactor this PR to raise an error if someone tries to add an index inline within a Either way, there's something that needs to be added because its really unclear that this is currently unsupported. |
I'm fine with it in column. Can you rebase? |
In case if we want to add a column into the existing table with index on it, we have to add column and index in two seperate lines. With this feature we don't need to write an extra line to add index for column. We can just use `index` option. Old behaviour in action: ``` change_table(:languages) do |t| t.string :country_code t.index: :country_code end ``` New behaviour in action: ``` change_table(:languages) do |t| t.string :country_code, index: true end ``` Exactly same behaviour is already exist for `create_table` migrations.
7ba022b
to
5e4c22d
Compare
@rafaelfranca done. |
index option added for change_table migrations
index option added for change_table migrations rails/rails#23593
In case if we want to add a column into the existing table
with index on it, we have to add column and index in two
seperate lines.
With this feature we don't need to write an extra line to
add index for column. We can just use
index
option.Old behaviour in action:
New behaviour in action:
Exactly same behaviour is already exist for
create_table
migrations.There was a pull request created by me which was about adding
index
option foradd_column
helper. I understand the concern behind closing it and it make sense but this addition is different from it. So I'm not pushing same idea again.