Class: CreateFollows

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/follow_system/templates/migration.rb

Overview

CreateFollows class

This class defines the create follows migration in follow system

Instance Method Summary collapse

Instance Method Details

#changeObject

Changes the database



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

def change
  ###
  # Follows table creation
  ###
  create_table :follows do |t|
    ###
    # Followee id field and followee type field definition
    ###
    t.references :followee, polymorphic: true

    ###
    # Follower id fiel and follower type field definition
    ###
    t.references :follower, polymorphic: true

    ###
    # Timestamps fields definition
    ###
    t.timestamps null: false
  end

  ###
  # Follows table followee id field and followee type field index addition
  ###
  add_index :follows, [:followee_id, :followee_type], name: "follows_followee_idx"

  ###
  # Follows table follower id field and follower type field index addition
  ###
  add_index :follows, [:follower_id, :follower_type], name: "follows_follower_idx"

  ###
  # Follows table followee id field and followee type field and follower id field and follower type field unique index addition
  ###
  add_index :follows, [:followee_id, :followee_type, :follower_id, :follower_type], name: "follows_followee_follower_idx", unique: true
end