20120711000839_move_admin_notes_to_comments.rb 1.3 KB

12345678910111213141516171819202122232425
  1. class MoveAdminNotesToComments < ActiveRecord::Migration
  2. def self.up
  3. remove_index :admin_notes, [:admin_user_type, :admin_user_id]
  4. rename_table :admin_notes, :active_admin_comments
  5. rename_column :active_admin_comments, :admin_user_type, :author_type
  6. rename_column :active_admin_comments, :admin_user_id, :author_id
  7. add_column :active_admin_comments, :namespace, :string
  8. add_index :active_admin_comments, [:namespace]
  9. add_index :active_admin_comments, [:author_type, :author_id]
  10. # Update all the existing comments to the default namespace
  11. say "Updating any existing comments to the #{ActiveAdmin.application.default_namespace} namespace."
  12. execute "UPDATE active_admin_comments SET namespace='#{ActiveAdmin.application.default_namespace}'"
  13. end
  14. def self.down
  15. remove_index :active_admin_comments, :column => [:author_type, :author_id]
  16. remove_index :active_admin_comments, :column => [:namespace]
  17. remove_column :active_admin_comments, :namespace
  18. rename_column :active_admin_comments, :author_id, :admin_user_id
  19. rename_column :active_admin_comments, :author_type, :admin_user_type
  20. rename_table :active_admin_comments, :admin_notes
  21. add_index :admin_notes, [:admin_user_type, :admin_user_id]
  22. end
  23. end