Fix old migration

This commit is contained in:
Essem 2024-12-29 00:06:41 -06:00
parent ddac944404
commit 470459c9b8
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C

View file

@ -7,21 +7,19 @@ class MoveEmojiReactionSettings < ActiveRecord::Migration[6.1]
setting_visible_reactions: 'visible_reactions',
}.freeze
class LegacySetting < ApplicationRecord
self.table_name = 'settings'
class Setting < ApplicationRecord
def var
self[:var]&.to_sym
end
def value
YAML.safe_load(self[:value], permitted_classes: [ActiveSupport::HashWithIndifferentAccess]) if self[:value].present?
YAML.safe_load(self[:value], permitted_classes: [ActiveSupport::HashWithIndifferentAccess, Symbol]) if self[:value].present?
end
end
def up
User.find_in_batches do |users|
previous_settings_for_batch = LegacySetting.where(thing_type: 'User', thing_id: users.map(&:id)).group_by(&:thing_id)
previous_settings_for_batch = Setting.where(thing_type: 'User', thing_id: users.map(&:id)).group_by(&:thing_id)
users.each do |user|
previous_settings = previous_settings_for_batch[user.id]&.index_by(&:var) || {}