3

When working on a project, I keep track of all the changes I make to a database in a notepad file. Then, later, I manually write all the changes in rails' db migration file.

But it should be possible to compare the schema of a backup of my database, with the new version of my database, and automatically detect the differences. And generate the rails db migration file automatically.

Is there a tool that can compare two database schema's and automatically generate rails' db migration files?

1
  • 2
    Don't change the schema file manually. Commented Apr 18, 2016 at 9:29

1 Answer 1

2

As far as I'm aware, there's no tool that will do it automatically, however, you can get most of the way there just using rake db:schema:dump with source control.

Create a new Rails project and do the following:

  1. Update database.yml to connect to your first database.
  2. Use rake db:schema:dump to populate schema.rb and commit schema.rb to git.
  3. Update database.yml to connect to your second database and again run rake db:schema:dump
  4. Use git diff on schema.rb to compare the changes. This can easily be mapped to a migration.

The benefit of using source control is that you can then test the migration by comparing schema.rb after the migration runs to the schema dump of the second database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.