Mike Nichols
Mike Nichols

Reputation: 119

Is it a good idea to have our CI server automatically run rails migrations and commit schema.rb?

At my company, we're seeing intermittent issues with fields appearing/disappearing, errant tables appearing, and conflicts in our schema.rb file. These problems have been happening consistently and waste our time.

I'm having a hard time convincing my co-worker that our migration/schema.rb problems can be fixed simply by using a standard workflow.

First, the facts:

I believe that (most of) our migration/schema.rb problems will be solved by following this simple rule:

Before you run a migration, always load your schema into a newly created database:

rake db:drop db:create db:schema:load db:migrate

Then, review your changes carefully to be confident that only the changes from your migration(s) are committed to schema.rb

My co-worker believes it would be better to not allow developers to change schema.rb, but instead have a task on our Jenkins server that would run migrations and automatically commit changes to schema.rb. He says that we should remove the human element from our process and automate the work, and this will not allow problems to happen in the future.

While I believe in automating away work, I don't believe this is the best solution, since it merely targets a symptom and not the cause. Automating git commits makes me nervous because so many things can go wrong. More importantly, separating migrations and their corresponding schema.rb changes seems like a really bad idea to me. We shouldn't continue to allow our developers to be ignorant of the negative impact of polluting schema.rb. We should instead teach them a better workflow that will avoid polluting schema.rb, and give them the knowledge to debug problems when they do occur in the future.

Can people please weigh in and recommend which of our solutions is better? Or a better solution we haven't thought of yet?

Upvotes: 1

Views: 120

Answers (0)

Related Questions