Class: CreateDebTables

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

Class Method Summary collapse

Class Method Details

.downObject



36
37
38
39
40
# File 'lib/generators/deb/templates/migration.rb', line 36

def self.down
  drop_table :deb_accounts
  drop_table :deb_transactions
  drop_table :deb_items
end

.upObject



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
# File 'lib/generators/deb/templates/migration.rb', line 2

def self.up
  create_table :deb_accounts do |t|
    t.string :name
    t.string :kind
    t.string :short_name, limit: 16
    t.references :accountable, polymorphic: true
    t.boolean :contra
    t.decimal :current_balance, precision: 20, scale: 2, default: 0
    t.timestamps
  end
  add_index :deb_accounts, :short_name
  add_index :deb_accounts, [:accountable_type, :accountable_id, :kind], name: "deb_accounts_default"

  create_table :deb_transactions do |t|
    t.string :description
    t.string :kind, limit: 16
    t.references :transactionable, polymorphic: true
    t.integer :rollback_transaction_id
    t.timestamps
  end
  add_index :deb_transactions, [:transactionable_type, :transactionable_id, :kind], name: "deb_transactions_default"

  create_table :deb_items do |t|
    t.string :kind
    t.integer :account_id
    t.integer :transaction_id
    t.decimal :amount, precision: 20, scale: 2, default: 0
    t.decimal :balance_before, precision: 20, scale: 2, default: 0
    t.decimal :balance_after, precision: 20, scale: 2, default: 0
  end 
  add_index :deb_items, :account_id
  add_index :deb_items, [:transaction_id, :kind]
end