Class: CreateRatingForTables

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

Class Method Summary collapse

Class Method Details

.downObject



28
29
30
31
# File 'lib/generators/rating_for/migration/templates/migration.rb', line 28

def self.down
  drop_table :ratings
  drop_table :rateable_elements
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
# File 'lib/generators/rating_for/migration/templates/migration.rb', line 2

def self.up
  create_table :rateable_elements do |t|
  	t.string  :element_type
  	t.string  :element_attribute
  	t.integer :element_id
  	t.float :avg_rating, :default => 0
  	t.integer :total_rating, :default => 0
  	t.integer :ratings_count, :default => 0
  	
    t.timestamps
  end
  
  create_table :ratings do |t|
    t.integer :value
    t.integer :rateable_element_id
    t.integer :rater_id
    t.string  :rater_type
    
    t.timestamps
  end
  
  add_index :ratings, :rateable_element_id
  add_index :ratings, [:rater_type, :rater_id]
  add_index :rateable_elements, [:element_type, :element_attribute, :element_id], :name => :rateable_elements_index
end