Skip to content

Commit

Permalink
Fix old migration
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEssem committed Jan 3, 2025
1 parent 31d5aa1 commit be64f5f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions db/migrate/20230215074425_move_emoji_reaction_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,19 @@ class User < ApplicationRecord; end
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) || {}
Expand Down

0 comments on commit be64f5f

Please sign in to comment.