Merge pull request #1216 from Retrospring/fix/missing-notification-created-at
Fix missing creation times on commented notifications
This commit is contained in:
commit
7bb8a343dc
|
@ -36,7 +36,7 @@ class Subscription < ApplicationRecord
|
|||
.where.not(user: source.user)
|
||||
.where.not(user_id: muted_by)
|
||||
.map do |s|
|
||||
{ target_id: source.id, target_type: Comment, recipient_id: s.user_id, new: true, type: Notification::Commented }
|
||||
{ target_id: source.id, target_type: Comment, recipient_id: s.user_id, new: true, type: Notification::Commented, created_at: source.created_at, updated_at: source.created_at }
|
||||
end
|
||||
|
||||
Notification.insert_all!(notifications) unless notifications.empty? # rubocop:disable Rails/SkipsModelValidations
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class BackfillMissingCreatedAtOnCommentedNotifications < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
execute <<~SQUIRREL
|
||||
UPDATE notifications
|
||||
SET created_at = comments.created_at, updated_at = comments.created_at
|
||||
FROM comments
|
||||
WHERE notifications.target_id = comments.id AND notifications.created_at IS NULL AND notifications.type = 'Notification::Commented'
|
||||
SQUIRREL
|
||||
|
||||
# clean up notifications for deleted comments
|
||||
Notification::Commented.where(created_at: nil).destroy_all
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2023_02_27_174822) do
|
||||
ActiveRecord::Schema.define(version: 2023_05_26_181715) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
|
Loading…
Reference in New Issue