2017-01-09 15:46:43 +01:00
|
|
|
class CreateRequests < ActiveRecord::Migration
|
|
|
|
def change
|
2017-01-16 23:19:13 +01:00
|
|
|
unless table_exists? :requests
|
|
|
|
create_table :requests do |t|
|
|
|
|
t.references :debtor, null: false
|
|
|
|
t.references :creditor, null: false
|
|
|
|
t.references :issuer, polymorphic: true, null: false
|
|
|
|
t.integer :amount, null: false, default: 0
|
|
|
|
t.string :message
|
2017-01-09 15:46:43 +01:00
|
|
|
|
2017-01-16 23:19:13 +01:00
|
|
|
t.integer :status, default: 0
|
2017-01-09 15:46:43 +01:00
|
|
|
|
2017-01-16 23:19:13 +01:00
|
|
|
t.timestamps null: false
|
|
|
|
end
|
2017-01-09 15:46:43 +01:00
|
|
|
end
|
|
|
|
|
2017-01-16 23:23:49 +01:00
|
|
|
add_index :requests, :debtor_id unless index_exists?(:requests, :debtor_id)
|
|
|
|
add_index :requests, :creditor_id unless index_exists?(:requests, :creditor_id)
|
|
|
|
add_index :requests, [:issuer_type, :issuer_id] unless index_exists?(:requests, [:issuer_type, :issuer_id])
|
2017-01-16 23:16:51 +01:00
|
|
|
|
2017-01-16 23:03:37 +01:00
|
|
|
add_foreign_key :requests, :users, column: :creditor_id
|
|
|
|
add_foreign_key :requests, :users, column: :debtor_id
|
2017-01-09 15:46:43 +01:00
|
|
|
end
|
|
|
|
end
|