mirror of
https://github.com/discourse/discourse.git
synced 2025-02-05 19:11:13 +00:00
The `notifications.id` has been migrated to bigint in previous commit 799a45a291e9f2bd94278f565e58874458768079. This commit migrates one of the related columns, `user_badges.notification_id`, to `bigint`.
21 lines
634 B
Ruby
21 lines
634 B
Ruby
# frozen_string_literal: true
|
|
|
|
class CopyUserBadgesNotificationIdValues < ActiveRecord::Migration[7.0]
|
|
disable_ddl_transaction!
|
|
|
|
def up
|
|
min_id, max_id = execute("SELECT MIN(id), MAX(id) FROM user_badges")[0].values
|
|
batch_size = 10_000
|
|
|
|
(min_id..max_id).step(batch_size) { |start_id| execute <<~SQL.squish } if min_id && max_id
|
|
UPDATE user_badges
|
|
SET new_notification_id = notification_id
|
|
WHERE id >= #{start_id} AND id < #{start_id + batch_size} AND notification_id IS NOT NULL AND new_notification_id IS NULL
|
|
SQL
|
|
end
|
|
|
|
def down
|
|
raise ActiveRecord::IrreversibleMigration
|
|
end
|
|
end
|