add_reference, ... index: true should be banded
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Problem
When you create a new column, add a new foreign key, and add an index, add_reference method is convenient. For exmaple, you can code like
def change
add_reference :model, :other_model, index: true, foreign_key: { on_delete: :cascade }
end
Then, it handles the above operations automagically. This is also described in our migration style guide
However, add_reference does not use { algorithm: :concurrently } by default. If accidentally someone ships the above migration to production, downtime would occur, as it locks table to add an index.
Solution
- Ban
add_reference, ... index: trueusage - Alternatively, we can introduce
add_concurrent_referencemethod - Alternatively, we can recommend manual way. (use
add_column,add_concurrent_index,add_concurrent_foreign_keyexample) - Update migration style guide
Edited by 🤖 GitLab Bot 🤖