main
 1class 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
11    # Update all the existing comments to the default namespace
12    say "Updating any existing comments to the #{ActiveAdmin.application.default_namespace} namespace."
13    comments_table_name = ActiveRecord::Migrator.proper_table_name("active_admin_comments")
14    execute "UPDATE #{comments_table_name} SET namespace='#{ActiveAdmin.application.default_namespace}'"
15  end
16
17  def self.down
18    remove_index  :active_admin_comments, :column => [:author_type, :author_id]
19    remove_index  :active_admin_comments, :column => [:namespace]
20    remove_column :active_admin_comments, :namespace
21    rename_column :active_admin_comments, :author_id, :admin_user_id
22    rename_column :active_admin_comments, :author_type, :admin_user_type
23    rename_table  :active_admin_comments, :admin_notes
24    add_index     :admin_notes, [:admin_user_type, :admin_user_id]
25  end
26end