From 8016fcab332a2945bc3ad9676111841af3bc7fee Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Tue, 15 Oct 2024 11:58:57 +0300 Subject: [PATCH] DEV: Drop old notification id columns (#28550) The `id` column of `notifications` table and `notification_id` columns of the other tables have been migrated to bigint in previous commits (for example, 799a45a). In order to run the migrations with zero downtime, the data had to be copied to new columns and swapped, but the old columns have been kept to allow for rollback. They are no longer needed now. --- app/models/notification.rb | 2 +- app/models/shelved_notification.rb | 2 +- app/models/user.rb | 1 + app/models/user_badge.rb | 2 +- ...9140226_drop_old_notification_id_columns.rb | 18 ++++++++++++++++++ .../app/models/chat/mention_notification.rb | 6 +++--- ...chat_mention_notifications_old_id_column.rb | 13 +++++++++++++ 7 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 db/post_migrate/20240829140226_drop_old_notification_id_columns.rb create mode 100644 plugins/chat/db/post_migrate/20240829140227_drop_chat_mention_notifications_old_id_column.rb diff --git a/app/models/notification.rb b/app/models/notification.rb index 42768c594da..356691b8ff7 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -2,7 +2,7 @@ class Notification < ActiveRecord::Base self.ignored_columns = [ - :old_id, # TODO: Remove when column is dropped. At this point, the migration to drop the column has not been writted. + :old_id, # TODO: Remove once 20240829140226_drop_old_notification_id_columns has been promoted to pre-deploy ] attr_accessor :acting_user diff --git a/app/models/shelved_notification.rb b/app/models/shelved_notification.rb index 57eba4b3978..633872f3d65 100644 --- a/app/models/shelved_notification.rb +++ b/app/models/shelved_notification.rb @@ -2,7 +2,7 @@ class ShelvedNotification < ActiveRecord::Base self.ignored_columns = [ - :old_notification_id, # TODO: Remove when column is dropped. At this point, the migration to drop the column has not been writted. + :old_notification_id, # TODO: Remove once 20240829140226_drop_old_notification_id_columns has been promoted to pre-deploy ] belongs_to :notification diff --git a/app/models/user.rb b/app/models/user.rb index 661dd9cf6bb..00e71a234d7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -6,6 +6,7 @@ class User < ActiveRecord::Base :salt, # TODO: Remove when column is dropped. At this point, the migration to drop the column has not been written. :password_hash, # TODO: Remove when column is dropped. At this point, the migration to drop the column has not been written. :password_algorithm, # TODO: Remove when column is dropped. At this point, the migration to drop the column has not been written. + :old_seen_notification_id, # TODO: Remove once 20240829140226_drop_old_notification_id_columns has been promoted to pre-deploy ] include Searchable diff --git a/app/models/user_badge.rb b/app/models/user_badge.rb index 5f4bfb889e2..b75160363d0 100644 --- a/app/models/user_badge.rb +++ b/app/models/user_badge.rb @@ -2,7 +2,7 @@ class UserBadge < ActiveRecord::Base self.ignored_columns = [ - :old_notification_id, # TODO: Remove when column is dropped. At this point, the migration to drop the column has not been writted. + :old_notification_id, # TODO: Remove once 20240829140226_drop_old_notification_id_columns has been promoted to pre-deploy ] belongs_to :badge diff --git a/db/post_migrate/20240829140226_drop_old_notification_id_columns.rb b/db/post_migrate/20240829140226_drop_old_notification_id_columns.rb new file mode 100644 index 00000000000..6e4b4f7a08b --- /dev/null +++ b/db/post_migrate/20240829140226_drop_old_notification_id_columns.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +class DropOldNotificationIdColumns < ActiveRecord::Migration[7.1] + DROPPED_COLUMNS = { + notifications: %i[old_id], + shelved_notifications: %i[old_notification_id], + users: %i[old_seen_notification_id], + user_badges: %i[old_notification_id], + } + + def up + DROPPED_COLUMNS.each { |table, columns| Migration::ColumnDropper.execute_drop(table, columns) } + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/plugins/chat/app/models/chat/mention_notification.rb b/plugins/chat/app/models/chat/mention_notification.rb index 31a5bb8f2e8..577ccc075fb 100644 --- a/plugins/chat/app/models/chat/mention_notification.rb +++ b/plugins/chat/app/models/chat/mention_notification.rb @@ -2,12 +2,12 @@ module Chat class MentionNotification < ActiveRecord::Base - self.table_name = "chat_mention_notifications" - self.ignored_columns = [ - :old_notification_id, # TODO remove once this column is removed. Migration to drop the column has not been written. + :old_notification_id, # TODO: Remove once 20240829140227_drop_chat_mention_notifications_old_id_column has been promoted to pre-deploy ] + self.table_name = "chat_mention_notifications" + belongs_to :chat_mention, class_name: "Chat::Mention" belongs_to :notification, dependent: :destroy end diff --git a/plugins/chat/db/post_migrate/20240829140227_drop_chat_mention_notifications_old_id_column.rb b/plugins/chat/db/post_migrate/20240829140227_drop_chat_mention_notifications_old_id_column.rb new file mode 100644 index 00000000000..d643ff99223 --- /dev/null +++ b/plugins/chat/db/post_migrate/20240829140227_drop_chat_mention_notifications_old_id_column.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class DropChatMentionNotificationsOldIdColumn < ActiveRecord::Migration[7.1] + DROPPED_COLUMNS = { chat_mention_notifications: %i[old_notification_id] } + + def up + DROPPED_COLUMNS.each { |table, columns| Migration::ColumnDropper.execute_drop(table, columns) } + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end