Class: AlterRecordHistoriesAddTransactionId

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/record_history/templates/alter_record_histories_add_transaction_id.rb

Class Method Summary collapse

Class Method Details

.downObject



11
12
13
# File 'lib/generators/record_history/templates/alter_record_histories_add_transaction_id.rb', line 11

def self.down
  remove_column :record_histories, :transaction_id
end

.upObject



2
3
4
5
6
7
8
9
10
# File 'lib/generators/record_history/templates/alter_record_histories_add_transaction_id.rb', line 2

def self.up
  add_column :record_histories, :transaction_id, :decimal
  RecordHistoryModel.all.each do |rec|
    rec.transaction_id = rec.created_at.to_f
    rec.save
  end
  change_column :record_histories, :transaction_id, :decimal, :null => false
  add_index :record_histories, :transaction_id
end