Sha256: 30447d24bbf5e8ec800f2c3bc815787cdfc1176875a301091af280ee2f6b6a02

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

###
# CreateFollows class
#
# This class defines the create follows migration in follow system
###
class CreateFollows < ActiveRecord::Migration[5.0]
  ###
  # Changes the database
  ###
  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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
follow_system-0.1.1 lib/generators/follow_system/templates/migration.rb
follow_system-0.1.0 lib/generators/follow_system/templates/migration.rb