I have been mucking with my development database and am getting ready to move it to production. I made some edits outside of rails, so I don’t have a migration for all of my changes. I know I can rake db:schema:dump to generate a schema.rb file, but can I apply that to an already populated production db without wiping the data? Something similar to rake db:schema:load without wiping the data?
If not, do I just need to manually create the migrations that would catch the production db up? If I do make those migrations, won’t all future calls to rake db:migrate on the dev box fail because the change in the migration already exists in the dev db?
The problem with
rake db:schema:loadis that it will forcefully create the tables, which you can see indb/schema.rb:What I would recommend is that you do create the missing migrations. You can fix your local dev database by adding the timestamps to the
schema_migrationstable manually. That is the consequence of changing your schema by hand.I personally always make sure that
rake db:migrate:reset(drop all tables and migrate from scratch) will produce the samedb/schema.rbasrake db:schema:dumpwould. Any change in the database schema must be automated by a migration. You could even make it part of your CI script, by runningrake db:migrate:resetand than asserting thatdb/schema.rbdidn’t change from what is in source control.