2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-30 23:06:56 -05:00
|
|
|
class CreateReplies < ActiveRecord::Migration[4.2]
|
2013-02-05 13:16:51 -06:00
|
|
|
def change
|
|
|
|
create_table :post_replies, id: false do |t|
|
|
|
|
t.references :post
|
|
|
|
t.integer :reply_id
|
2017-08-07 10:48:36 -05:00
|
|
|
t.timestamps null: false
|
2013-02-05 13:16:51 -06:00
|
|
|
end
|
|
|
|
|
2023-01-09 05:59:41 -06:00
|
|
|
add_index :post_replies, %i[post_id reply_id], unique: true
|
2013-02-05 13:16:51 -06:00
|
|
|
|
|
|
|
execute "INSERT INTO post_replies (post_id, reply_id, created_at, updated_at)
|
|
|
|
SELECT p2.id, p.id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
|
|
|
|
FROM posts AS p
|
|
|
|
INNER JOIN posts AS p2 on p2.post_number = p.reply_to_post_number AND p2.forum_thread_id = P.forum_thread_id
|
|
|
|
WHERE p.forum_thread_id IS NOT NULL"
|
|
|
|
end
|
|
|
|
end
|