-
Notifications
You must be signed in to change notification settings - Fork 79
/
008_create_wk_payment.rb
75 lines (64 loc) · 2.47 KB
/
008_create_wk_payment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class CreateWkPayment < ActiveRecord::Migration[4.2]
def change
add_reference :wk_invoices, :parent, polymorphic: true, index: true
add_reference :wk_contracts, :parent, polymorphic: true, index: true
add_reference :wk_account_projects, :parent, polymorphic: true, index: true
reversible do |dir|
dir.up do
# add a CHECK constraint
execute <<-SQL
UPDATE wk_invoices set parent_id = account_id, parent_type = 'WkAccount' ;
SQL
execute <<-SQL
UPDATE wk_contracts set parent_id = account_id, parent_type = 'WkAccount' ;
SQL
execute <<-SQL
UPDATE wk_account_projects set parent_id = account_id, parent_type = 'WkAccount' ;
SQL
end
dir.down do
execute <<-SQL
UPDATE wk_invoices set account_id = parent_id ;
SQL
execute <<-SQL
UPDATE wk_contracts set account_id = parent_id ;
SQL
execute <<-SQL
UPDATE wk_account_projects set account_id = parent_id;
SQL
end
end
create_table :wk_payments do |t|
t.date :payment_date
t.string :description
t.references :payment_type, :class => "wk_crm_enumerations"
t.string :reference_number
t.references :parent, polymorphic: true, index: true
t.references :created_by_user, :class => "User"
t.references :modified_by_user, :class => "User"
t.timestamps null: false
end
create_table :wk_payment_items do |t|
t.float :amount
t.column :currency, :string, :limit => 5
t.boolean :is_deleted, :default => false
t.references :payment, :class => "wk_payments", :null => true, :index => true
t.references :invoice, :class => "wk_invoices", :null => true, :index => true
t.references :gl_transaction, :class => "wk_gl_transactions", :null => true, :index => true
t.references :created_by_user, :class => "User"
t.references :modified_by_user, :class => "User"
t.timestamps null: false
end
create_table :wk_ex_currency_rates do |t|
t.column :from_c, :string, :limit => 5, :default => '$'
t.column :to_c, :string, :limit => 5, :default => '$'
t.float :ex_rate
t.timestamps null: false
end
add_reference :wk_invoice_items, :credit_invoice, :class => "wk_invoices"
add_reference :wk_invoice_items, :credit_payment_item, :class => "wk_payment_items"
remove_reference :wk_invoices, :account, :class => "wk_accounts", :null => true
remove_reference :wk_contracts, :account, :class => "wk_accounts", :null => true
remove_reference :wk_account_projects, :account, :class => "wk_accounts", :null => true
end
end