Class: KeeprMigration

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

Class Method Summary collapse

Class Method Details

.downObject



66
67
68
69
70
71
# File 'lib/generators/keepr/migration/templates/migration.rb', line 66

def self.down
  drop_table :keepr_postings
  drop_table :keepr_journals
  drop_table :keepr_accounts
  drop_table :keepr_groups
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
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
# File 'lib/generators/keepr/migration/templates/migration.rb', line 2

def self.up
  create_table :keepr_groups, force: true do |t|
    t.integer    :target, :null => false
    t.string     :number
    t.string     :name, :null => false
    t.boolean    :is_result, :null => false, :default => false
    t.string     :ancestry
  end
  add_index :keepr_groups, :ancestry

  create_table :keepr_taxes, force: true do |t|
    t.string     :name, :null => false
    t.string     :description
    t.decimal    :value, :precision => 8, :scale => 2, :null => false
    t.references :keepr_account, :null => false
  end
  add_index :keepr_taxes, :keepr_account_id

  create_table :keepr_cost_centers, force: true do |t|
    t.string     :number, :null => false
    t.string     :name, :null => false
    t.text       :note
  end

  create_table :keepr_accounts, force: true do |t|
    t.integer    :number, :null => false
    t.string     :ancestry
    t.string     :name, :null => false
    t.integer    :kind, :null => false
    t.references :keepr_group
    t.references :accountable, :polymorphic => true
    t.references :keepr_tax
    t.datetime   :created_at
    t.datetime   :updated_at
  end
  add_index :keepr_accounts, :number
  add_index :keepr_accounts, :ancestry
  add_index :keepr_accounts, [:accountable_type, :accountable_id]
  add_index :keepr_accounts, :keepr_group_id
  add_index :keepr_accounts, :keepr_tax_id

  create_table :keepr_journals, force: true do |t|
    t.string   :number
    t.date     :date, :null => false
    t.string   :subject
    t.references :accountable, :polymorphic => true
    t.text     :note
    t.datetime :created_at
    t.datetime :updated_at
  end
  add_index :keepr_journals, :date
  add_index :keepr_journals, [:accountable_type, :accountable_id], :name => 'index_keepr_journals_on_accountable'

  create_table :keepr_postings, force: true do |t|
    t.references :keepr_account, :null => false
    t.references :keepr_journal, :null => false
    t.decimal    :amount, :precision => 8, :scale => 2, :null => false
    t.references :keepr_cost_center
  end
  add_index :keepr_postings, :keepr_account_id
  add_index :keepr_postings, :keepr_journal_id
  add_index :keepr_postings, :keepr_cost_center_id
end