Class: CreateBookmarks

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

Overview

CreateBookmarks class

This class defines the create bookmarks migration in bookmark 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/bookmark_system/templates/migration.rb', line 10

def change
  ###
  # Bookmarks table creation
  ###
  create_table :bookmarks do |t|
    ###
    # Bookmarkee id field and bookmarkee type field definition
    ###
    t.references :bookmarkee, polymorphic: true

    ###
    # Bookmarker id fiel and bookmarker type field definition
    ###
    t.references :bookmarker, polymorphic: true

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

  ###
  # Bookmarks table bookmarkee id field and bookmarkee type field index addition
  ###
  add_index :bookmarks, [:bookmarkee_id, :bookmarkee_type], name: "bookmarks_bookmarkee_idx"

  ###
  # Bookmarks table bookmarker id field and bookmarker type field index addition
  ###
  add_index :bookmarks, [:bookmarker_id, :bookmarker_type], name: "bookmarks_bookmarker_idx"

  ###
  # Bookmarks table bookmarkee id field and bookmarkee type field and bookmarker id field and bookmarker type field unique index addition
  ###
  add_index :bookmarks, [:bookmarkee_id, :bookmarkee_type, :bookmarker_id, :bookmarker_type], name: "bookmarks_bookmarkee_bookmarker_idx", unique: true
end