Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I wrote a migration file with the following code:

class AddScheduleIdToPlayers < ActiveRecord::Migration
  def change
        add_column :players, :schedule_id, :integer
        add_column :schedules, :coach_id, :integer
  end
end

Is it bad form to not create two migration files, one for each change, or is this fine?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You want to keep related changes together. For example, if you implement bidirectional relation and add columns/tables to suffice AR relations you want to keep those in one migration.

If changes in schema are not related to each other (parts of different features, for example) it's better to keep them in separate migrations.

I do a mental experiment when I'm not sure. I try to break up migration for the smallest possible pieces and then check if my feature still works if I take down only one of the pieces. If it is that piece is likely doesn't belong to this migration.

Yours look to me like it can be split into two migrations. It seem to be you have two features here. One is about adding schedules for players and another for adding coaches to schedules.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.