cirandas.net

ref: master

db/migrate/20141014205254_change_chat_messages_columns_and_add_indexes.rb


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class ChangeChatMessagesColumnsAndAddIndexes < ActiveRecord::Migration
  def up
    change_table :chat_messages do |t|
      t.change :from_id, :integer, :null => false
      t.change :to_id, :integer, :null => false
      t.change :body, :text
    end
    add_index :chat_messages, :from_id
    add_index :chat_messages, :to_id
    add_index :chat_messages, :created_at
  end

  def down
    remove_index :chat_messages, :from_id
    remove_index :chat_messages, :to_id
    remove_index :chat_messages, :created_at
    change_table :chat_messages do |t|
      t.change :from_id, :integer, :null => true
      t.change :to_id, :integer, :null => true
      t.change :body, :string
    end
  end
end