class <%= @activity.camelize.gsub(/\s/, '') %> < ActiveRecord::Migration def self.up <% @columns[:added].each do |field, options| %> add_column :<%= @table_name %>, :<%= field %>, :<%= options.delete(:type) %><%= (options.blank?)? '': ", "+options.inspect[1..-2] %> <% end -%> <% @columns[:changed].each do |field, options, old_options| %> change_column :<%= @table_name %>, :<%= field %>, :<%= options.delete(:type) %><%= (options.blank?)? '': ", "+options.inspect[1..-2] %> <% end -%> <% @columns[:transferred].each do |source, target| %> puts "-- copy data from :<%= source %> to :<%= target %>" <%= @table_name.classify %>.update_all("<%= target %> = <%= source %>") <% end -%> <% @columns[:renamed].each do |old_name, new_name| %> rename_column :<%= @table_name %>, :<%= old_name %>, :<%= new_name %> <% end -%> <% @columns[:deleted].each do |field, options| %> remove_column :<%= @table_name %>, :<%= field %> <% end -%> <% @indexes.each do |index, options| %> add_index :<%= @table_name %>, <%= index.inspect %> <% end -%> end def self.down <% @columns[:deleted].each do |field, options| %> add_column :<%= @table_name %>, :<%= field %>, :<%= options.delete(:type) %><%= (options.blank?)? '': ", "+options.inspect[1..-2] %> <% end -%> <% @columns[:renamed].each do |old_name, new_name| %> rename_column :<%= @table_name %>, :<%= new_name %>, :<%= old_name %> <% end -%> <% @columns[:transferred].each do |source, target| %> puts "-- copy data from :<%= target %> to :<%= source %>" <%= @table_name.classify %>.update_all("<%= source %> = <%= target %>") <% end -%> <% @columns[:changed].each do |field, options, old_options| %> change_column :<%= @table_name %>, :<%= field %>, :<%= old_options.delete(:type) %><%= (old_options.blank?)? '': ", "+old_options.inspect[1..-2] %> <% end -%> <% @columns[:added].each do |field, options| %> remove_column :<%= @table_name %>, :<%= field %> <% end -%> end end