056_create_notifications.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:1k
源码类别:

Ajax

开发平台:

Others

  1. class CreateNotifications < ActiveRecord::Migration
  2.   class OldNotification < ActiveRecord::Base
  3.   end
  4.   class Notification < ActiveRecord::Base
  5.   end
  6.   def self.up
  7.     rename_table :notifications, :old_notifications
  8.     create_table :notifications do |t|
  9.       t.column :content_id, :integer
  10.       t.column :user_id, :integer
  11.       t.column :created_at, :datetime
  12.       t.column :updated_at, :datetime
  13.     end
  14.     OldNotification.reset_column_information
  15.     Notification.reset_column_information
  16.     if $schema_generator
  17.       OldNotification.find(:all).each do |on|
  18.         Notification.create!(on.attributes)
  19.       end
  20.     end
  21.     drop_table :old_notifications
  22.   end
  23.   def self.down
  24.     remove_column :notifications, :id
  25.     rename_column :notifications, :user_id, :notify_user_id
  26.     rename_column :notifications, :content_id, :notify_content_id
  27.   end
  28. end