Вопрос

I created an application and uploaded it to a server to test Capistrano.

On my local machine, I continued to develop the app and created a database for my project, but I accidentally deleted some of my earlier migrations that the production server has yet to run.

I figure the solution is to:

completely delete all the tables on my production's database then... run rake db:schema:dump

Then create one migration file (deleting the rest) and pasting the current schema (from my schema dump) into that migration. Then running that one migration on the production server.

But I want to know if there is any downside to this? And if there is a better way...

Using Ubuntu 12 Server, Rails 4, Ruby 2.0.0

Это было полезно?

Решение

You don't need to drop all your tables in prod. Instead, create the big migration file you described, but then manually record it as applied in prod.

After all, the point of a migration is to apply changes to the DB. In your case that's only needed outside of your production environment.

Manually recording the migration is as simple as inserting the migration timestamp into the schema_migrations table:

mysql> select * from schema_migrations;
+----------------+
| version        |
+----------------+
| 20120504193548 |
| 20120508160150 |
| 20120518135330 |
| 20120523163509 |
...

So just execute the appropriate INSERT and rails will ignore the migration.

PS - In the future, use source control so you can just simply restore the file from a prior version!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top