aboutsummaryrefslogblamecommitdiffstats
path: root/railties/lib/rails_generator/generators/components/migration/templates/migration.rb
blob: e47f3afd49fec5d3e46d27ecb1295fc2028cb24e (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                                     


                                                                                                                                                 

     


                                                                                                                                                                                

     
class <%= class_name.underscore.camelize %> < ActiveRecord::Migration
  def self.up<% attributes.each do |attribute| %>
    <%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end -%>
  <% end %>
  end

  def self.down<% attributes.reverse.each do |attribute| %>
    <%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end -%>
  <% end %>
  end
end