Class: AddMerryGoRoundAggregations

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/rails/generators/merry_go_round/install/templates/add_aggregations.rb

Instance Method Summary collapse

Instance Method Details

#changeObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rails/generators/merry_go_round/install/templates/add_aggregations.rb', line 2

def change
  create_table :merry_go_round_aggregations do |t|
    # The name of whatever you're tracking
    t.string :key, null: false

    # The integer value of your count
    t.integer :value, null: false, default: 0

    # When it was counted rounded to a normalized time
    t.datetime :timestamp, null: false

    # A string representing the granularity (minute, hour, day, week, month, year)
    t.string :granularity, null: false

    # Foreign key for tree structure
    t.integer :parent_id
  end

  add_index :merry_go_round_aggregations, [:granularity, :timestamp, :key, :parent_id], name: 'merry_go_round_aggregations_kgtp'
  add_index :merry_go_round_aggregations, [:parent_id, :granularity, :timestamp], name: 'merry_go_round_aggregations_pgt'
end