Class: CreateTalkieComments

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/talkie/templates/create_talkie_comments.rb

Class Method Summary collapse

Class Method Details

.downObject



37
38
39
# File 'lib/generators/talkie/templates/create_talkie_comments.rb', line 37

def self.down
  drop_table :talkie_comments
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
27
28
29
30
31
32
33
34
35
# File 'lib/generators/talkie/templates/create_talkie_comments.rb', line 2

def self.up
  create_table :talkie_comments do |t|
    t.string   :creator_type
    t.integer  :creator_id
    t.integer  :commentable_id
    t.string   :commentable_type
    t.text     :body, null: false
    t.integer  :parent_id
    t.integer  :lft
    t.integer  :rgt
    t.integer  :children_count, default: 0

    t.timestamps null: false
  end

  add_index :talkie_comments, :commentable_id
  add_index :talkie_comments, :commentable_type
  add_index :talkie_comments, [:creator_id, :creator_type],
            name: 'index_talkie_comments_on_creator_id_and_creator_type'

  create_table :talkie_subscriptions do |t|
    t.string   :subscriber_type, null: false
    t.integer  :subscriber_id, null: false
    t.integer  :comment_id, null: false

    t.timestamps null: false
  end

  add_index :talkie_subscriptions, [:subscriber_id, :subscriber_type, :comment_id],
    unique: true,
    name: 'index_talkie_subscriptions_on_s_id_and_s_type_and_c_id'

  add_index :talkie_subscriptions, :comment_id
end