Class: CreateReportableCache

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

Class Method Summary collapse

Class Method Details

.downObject



33
34
35
36
37
38
# File 'lib/generators/reportable_migration/templates/migration.rb', line 33

def self.down
  remove_index :reportable_cache, :name => :name_model_grouping_agregation
  remove_index :reportable_cache, :name => :name_model_grouping_aggregation_period

  drop_table :reportable_cache
end

.upObject



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

def self.up
  create_table :reportable_cache, :force => true do |t|
    t.string   :model_class_name,       :null => false, :limit => 100
    t.string   :report_name,      :null => false, :limit => 100
    t.string   :grouping,         :null => false, :limit => 10
    t.string   :aggregation,      :null => false, :limit => 10
    t.string   :conditions,       :null => false, :limit => 100
    t.float    :value,            :null => false,                :default => 0
    t.datetime :reporting_period, :null => false

    t.timestamps
  end

  add_index :reportable_cache, [
    :model_class_name,
    :report_name,
    :grouping,
    :aggregation,
    :conditions
  ], :name => :name_model_grouping_agregation
  add_index :reportable_cache, [
    :model_class_name,
    :report_name,
    :grouping,
    :aggregation,
    :conditions,
    :reporting_period
  ], :unique => true, :name => :name_model_grouping_aggregation_period
end