diff --git a/db/migrate/20230215074423_move_user_settings.rb b/db/migrate/20230215074423_move_user_settings.rb index 86231e49e8..e94f04138a 100644 --- a/db/migrate/20230215074423_move_user_settings.rb +++ b/db/migrate/20230215074423_move_user_settings.rb @@ -43,7 +43,17 @@ class MoveUserSettings < ActiveRecord::Migration[6.1] must_be_follower: 'interactions.must_be_follower', must_be_following: 'interactions.must_be_following', must_be_following_dm: 'interactions.must_be_following_dm', + # Glitch-soc additions + trending_link: 'notification_emails.link_trends', + trending_status: 'notification_emails.status_trends', }.freeze, + # Glitch-soc additions + favourite_modal: 'web.favourite_modal', + system_emoji_font: 'web.use_system_emoji_font', + hide_followers_count: 'hide_followers_count', + default_content_type: 'default_content_type', + flavour: 'flavour', + skin: 'skin', }.freeze class LegacySetting < ApplicationRecord diff --git a/db/migrate/20230215074424_move_glitch_user_settings.rb b/db/migrate/20230215074424_move_glitch_user_settings.rb deleted file mode 100644 index 2c432dc6a0..0000000000 --- a/db/migrate/20230215074424_move_glitch_user_settings.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -class MoveGlitchUserSettings < ActiveRecord::Migration[6.1] - disable_ddl_transaction! - - class User < ApplicationRecord; end - - MAPPING = { - favourite_modal: 'web.favourite_modal', - system_emoji_font: 'web.use_system_emoji_font', - hide_followers_count: 'hide_followers_count', - default_content_type: 'default_content_type', - flavour: 'flavour', - skin: 'skin', - notification_emails: { - trending_link: 'notification_emails.link_trends', - trending_status: 'notification_emails.status_trends', - }.freeze, - }.freeze - - class LegacySetting < ApplicationRecord - self.table_name = 'settings' - - def var - self[:var]&.to_sym - end - - def value - 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) - - users.each do |user| - previous_settings = previous_settings_for_batch[user.id]&.index_by(&:var) || {} - user_settings = Oj.load(user.settings || '{}') - user_settings.delete('theme') - - MAPPING.each do |legacy_key, new_key| - value = previous_settings[legacy_key]&.value - - next if value.nil? - - if value.is_a?(Hash) - value.each do |nested_key, nested_value| - user_settings[MAPPING[legacy_key][nested_key.to_sym]] = nested_value - end - else - user_settings[new_key] = value - end - end - - user.update_column('settings', Oj.dump(user_settings)) - end - end - end - - def down; end -end