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

Ajax

开发平台:

Others

  1. class SeparateEntriesAndFeedback < ActiveRecord::Migration
  2.   class Content < ActiveRecord::Base
  3.   end
  4.   class Feedback < ActiveRecord::Base
  5.   end
  6.   def self.up
  7.     # Comment this out once you've made a backup
  8.     create_table :feedback, :force => true do |t|
  9.       t.column "type",             :string
  10.       t.column "title",            :string
  11.       t.column "author",           :string
  12.       t.column "body",             :text
  13.       t.column "extended",         :text
  14.       t.column "excerpt",          :text
  15.       t.column "keywords",         :string
  16.       t.column "created_at",       :datetime
  17.       t.column "updated_at",       :datetime
  18.       t.column "user_id",          :integer
  19.       t.column "permalink",        :string
  20.       t.column "guid",             :string
  21.       t.column "text_filter_id",   :integer
  22.       t.column "whiteboard",       :text
  23.       t.column "article_id",       :integer
  24.       t.column "email",            :string
  25.       t.column "url",              :string
  26.       t.column "ip",               :string,  :limit => 40
  27.       t.column "blog_name",        :string
  28.       t.column "name",             :string
  29.       t.column "published",        :boolean, :default => false
  30.       t.column "allow_pings",      :boolean
  31.       t.column "allow_comments",   :boolean
  32.       t.column "blog_id",          :integer, :null => false
  33.       t.column "published_at",     :datetime
  34.       t.column "state",            :text
  35.       t.column "status_confirmed", :boolean
  36.     end
  37.     # Forgot to fixup the state field earlier. Thanks to Ryan Kinderman for the spot.
  38.     Content.transaction do
  39.       Content.update_all("state = 'spam'", :state => 'ContentState::Spam')
  40.       Content.update_all("state = 'ham'", :state => 'ContentState::Ham')
  41.       Content.update_all("state = 'presumed_spam'", :state => 'ContentState::PresumedSpam')
  42.       Content.update_all("state = 'presumed_ham'", :state => 'ContentState::PresumedHam')
  43.       Content.update_all("state = 'published'", :state => 'ContentState::Published')
  44.       Content.update_all("state = 'publication_pending'", :state => 'ContentState::PublicationPending')
  45.       Content.update_all("state = 'draft'", :state => 'ContentState::Draft')
  46.       Content.update_all("state = 'withdrawn'", :state => 'ContentState::Withdrawn')
  47.     end
  48.     Content.transaction do
  49.       Feedback.transaction do
  50.         Content.find(:all, :conditions => {:type => %w{ Comment Trackback }}).each do |content|
  51.           Feedback.new(content.attributes) do |fb|
  52.             fb[:type] = content[:type]
  53.             fb.published = (fb.state == 'ham' || fb.state == 'presumed_ham')
  54.             fb.save!
  55.           end
  56.         end
  57.         Content.delete_all(:type => %w{ Comment Trackback })
  58.       end
  59.     end
  60.   end
  61.   def self.down
  62.     Content.transaction do
  63.       Feedback.transaction do
  64.         Feedback.find(:all).each do |fb|
  65.           Content.new(fb.attributes) do |cnt|
  66.             cnt[:type] = fb[:type]
  67.             cnt.save!
  68.           end
  69.         end
  70.       end
  71.     end
  72.     drop_table :feedback
  73.   end
  74. end