Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between self.up and up in rails migration

I have noticed that some tutorials use self.up and self.down for migration methods. I understand that the self keyword indicates the method belongs to the instance only, but do they actually make a difference?

like image 368
John Jiang Avatar asked Sep 30 '11 16:09

John Jiang


People also ask

What is up and down in rails migration?

When you run rails db:migrate, the up method is executed, whereas rails db:rollback executes the down method. Simply, up runs the migration, down rolls the migration back.

What is up and down methods in migration?

The up method is called when migrating “up” the database – forward in time – while the down method is called when migrating “down” the database – or, back in time. In other words, the up method is a set of directions for running a migration, while the down method is a set of instructions for reverting a migration.

How rails db Migrate works?

When you run db:migrate, rails will check a special table in the database which contains the timestamp of the last migration applied to the database. It will then apply all of the migrations with timestamps after that date and update the database table with the timestamp of the last migration.

Which command is true 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

This is a change in Rails 3.1 - it used to have to be self.up and self.down, but now there has been a restructuring to allow them to just be up or down, and the associated method "change".

like image 191
Steve Hill Avatar answered Nov 06 '22 05:11

Steve Hill