From fbcd14ff7e18c8689426433aa5ad673c9ebd6409 Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 6 Dec 2024 11:58:18 +0100 Subject: [PATCH] Always remove setting keys in legacy user settings migrations (#33196) --- ...205135901_remove_legacy_user_settings_data.rb | 16 ++++++++++++++++ ...135925_remove_legacy_user_settings_columns.rb | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/db/migrate/20241205135901_remove_legacy_user_settings_data.rb b/db/migrate/20241205135901_remove_legacy_user_settings_data.rb index 09cc80842c..82f86aad14 100644 --- a/db/migrate/20241205135901_remove_legacy_user_settings_data.rb +++ b/db/migrate/20241205135901_remove_legacy_user_settings_data.rb @@ -8,6 +8,22 @@ class RemoveLegacyUserSettingsData < ActiveRecord::Migration[7.2] thing_type IS NOT NULL AND thing_id IS NOT NULL SQL + + # When running these migrations on mastodon.social, we saw 'notification_emails' + # and 'interactions' records that were not associated to a user and caused a + # migration issue. + # While I have not been able to pinpoint the exact cause of the issue, it is likely + # related to the settings system changes made in b11fdc3ae3f90731c01149a5a36dc64e065d4ea2. + # So, delete a few user settings that should already have been deleted. + connection.execute(<<~SQL.squish) + DELETE FROM settings + WHERE var IN ( + 'notification_emails', 'interactions', 'boost_modal', 'auto_play_gif', + 'delete_modal', 'system_font_ui', 'default_sensitive', 'unfollow_modal', + 'reduce_motion', 'display_sensitive_media', 'hide_network', 'expand_spoilers', + 'display_media', 'aggregate_reblogs', 'show_application', 'advanced_layout', + 'use_blurhash', 'use_pending_items') + SQL end def down diff --git a/db/post_migrate/20241205135925_remove_legacy_user_settings_columns.rb b/db/post_migrate/20241205135925_remove_legacy_user_settings_columns.rb index f713f18f25..3f0eaec4ed 100644 --- a/db/post_migrate/20241205135925_remove_legacy_user_settings_columns.rb +++ b/db/post_migrate/20241205135925_remove_legacy_user_settings_columns.rb @@ -15,6 +15,22 @@ class RemoveLegacyUserSettingsColumns < ActiveRecord::Migration[7.2] AND thing_id IS NOT NULL SQL + # When running these migrations on mastodon.social, we saw 'notification_emails' + # and 'interactions' records that were not associated to a user and caused a + # migration issue. + # While I have not been able to pinpoint the exact cause of the issue, it is likely + # related to the settings system changes made in b11fdc3ae3f90731c01149a5a36dc64e065d4ea2. + # So, delete a few user settings that should already have been deleted. + connection.execute(<<~SQL.squish) + DELETE FROM settings + WHERE var IN ( + 'notification_emails', 'interactions', 'boost_modal', 'auto_play_gif', + 'delete_modal', 'system_font_ui', 'default_sensitive', 'unfollow_modal', + 'reduce_motion', 'display_sensitive_media', 'hide_network', 'expand_spoilers', + 'display_media', 'aggregate_reblogs', 'show_application', 'advanced_layout', + 'use_blurhash', 'use_pending_items') + SQL + add_index :settings, :var, unique: true, algorithm: :concurrently remove_index :settings, [:thing_type, :thing_id, :var], name: :index_settings_on_thing_type_and_thing_id_and_var, unique: true