Search code examples
mysqlruby-on-railsrails-migrationsdumb-data

Loading the DB dumb, and running all the migrations


For a Rails project, if you are given a DB dump, what's gong to be the way?

  1. I run all the migrations, and then I load the DB dump.
  2. I load just the DB dump.

In point 2, if I load just the DB dump, and I, then add a new migration to my project. So then, running rake db:migrate will only run the new migration, since the old migrations have already been run by loading DB dump.

Or, loading a DB dump will have nothing to do with running migrations. A migration will only be marked up if you have run rake db:migrate?

Note: The DB dumb isn't Rails schema, it has been generated by MySQL, and it contains all the data a fellow developer has.


Solution

  • I would first load the db dump, as it also contains all you data and the current schema structure.

    running rake db:migrate will only run the new migration

    This depends. If your db dump has a schema_migrations table, that lists all the previously applied migrations, it will not apply the migrations. Otherwise, it will try to and fail.

    You basically need these steps:

    1. Import your dump
    2. Create a Rails schema (rake db:schema:dump)
    3. If you have newer migrations, run them