Backfill missing created_at on comment notifications

This commit is contained in:
Karina Kwiatek 2023-05-26 20:39:53 +02:00
parent f1863e5309
commit 84d4ac3dc6
2 changed files with 18 additions and 1 deletions

View File

@ -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

View File

@ -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"