What to do def self.up, def up, def self.down, def down mean?

Can someone please explain to me what is the difference between the following things?

  • def self.up
  • def up
  • def self.down
  • def down
+5
source share
2 answers

self.upand upcontains the code executed by migrations at execution rake db:migrate. self.up- older version up. I'm not sure when they introduced this, but before 3.0, they used self.up.

self.downand downshould contain code that cancels the effect of the methods up. therefore, if you created a table on up, you must drop this table on down. These methods are called at startup rake db:rollback.

, change, , , , , .

+10

def self.up - ( : Klass.up), def up - ( ). down.

+3

All Articles