Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usefulness of db migrations rollback

Many people talking about db migrations, especially about its rollback possibility.

I doubt, whether it is useful at all, because schema of db and model are tightly connected with application logic (MVC).

Suppose i've done rollback of some migration. And what ? The application will not work, because its logic fully relies on db.

What are the use cases of rollback ability for db migrations ?


Update 1

The main question

Why the rollback is presented as a feature, when i need to change the code ?

I don't create the migrations, like "add_another_field_to_table". Instead, each migration file fully describes each table in DB. When i need to change something in my DB, i just change the migration file, but don't roll it back.

Really, if i rollback the migration, it does't brings me back in time, like a version control does. I have a lot of work, when changes are planned and rollback gives me nothing.

like image 473
AntonAL Avatar asked Sep 27 '10 07:09

AntonAL


People also ask

What does a migration rollback do?

rollback all means it will reset all migration. so if you change anything on migration file then it will recreate and affect it.

What is the purpose of db migration?

In a database migration, you move data from source databases to target databases. After the data is completely migrated, you delete source databases and redirect client access to the target databases.

How do I rollback a specific migration?

You can rollback your migration by using rake db:rollback with different options. The syntax will be different according to your requirements.

Which command is used to rollback migration in Rails?

You must rollback the migration (for example with bin/rails db:rollback ), edit your migration, and then run bin/rails db:migrate to run the corrected version.


1 Answers

The point of rollback is that you rollback code and DB at the same time. The scenario is you upgrade your code and your DB on your production server, then you find a bug and you really need to go back. So rollback your code and use your down migration to roll back your DB.

like image 156
James Avatar answered Oct 29 '22 22:10

James