discourse/db/migrate/20240826121502_copy_shelved_notifications_notification_id_values.rb
Bianca Nenciu ec8ba5a0b9
DEV: Migrate shelved_notifications#notification_id to bigint (#28549)
DEV: Migrate shelved_notifications#notification_id to bigint

The `notifications.id` has been migrated to `bigint` in previous commit
799a45a291e9f2bd94278f565e58874458768079.
2024-08-27 10:56:00 +08:00

21 lines
643 B
Ruby

# frozen_string_literal: true
class CopyShelvedNotificationsNotificationIdValues < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
min_id, max_id = execute("SELECT MIN(id), MAX(id) FROM shelved_notifications")[0].values
batch_size = 10_000
(min_id..max_id).step(batch_size) { |start_id| execute <<~SQL.squish } if min_id && max_id
UPDATE shelved_notifications
SET new_notification_id = notification_id
WHERE id >= #{start_id} AND id < #{start_id + batch_size} AND notification_id != new_notification_id
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end