Skip to content

A platform for community discussion. Free, open, simple.

FIX: Ensure the reviewable.type_source migration is run post-deploy. (#31663)

Gary Pendergastf024bc4c6f96
diff --git a/db/migrate/20250212045125_add_type_source_to_reviewable.rb b/db/migrate/20250212045125_add_type_source_to_reviewable.rb
index 2be939f5e08..4cc0dfb4d5e 100644
--- a/db/migrate/20250212045125_add_type_source_to_reviewable.rb
+++ b/db/migrate/20250212045125_add_type_source_to_reviewable.rb
@@ -4,6 +4,8 @@ class AddTypeSourceToReviewable < ActiveRecord::Migration[7.2]
add_column :reviewables, :type_source, :string, null: false, default: "unknown"
# Migrate known reviewables to have a type_source
+ # This process is repeated in db/post_migrate/20250306045125_populate_type_source_in_reviewable.rb,
+ # to ensure that the column is populated after migrated servers are deployed to production.
known_reviewables = {
"chat" => %w[ReviewableChatMessage],
"core" => %w[ReviewableFlaggedPost ReviewableQueuedPost ReviewableUser ReviewablePost],
@@ -19,9 +21,11 @@ class AddTypeSourceToReviewable < ActiveRecord::Migration[7.2]
}
known_reviewables.each do |plugin, types|
- types.each do |type|
- Reviewable.where(type: type, type_source: "unknown").update_all(type_source: plugin)
- end
+ DB.exec(
+ "UPDATE reviewables SET type_source = :plugin WHERE type_source = 'unknown' AND type IN (:types)",
+ plugin: plugin,
+ types: types,
+ )
end
end
end
diff --git a/db/post_migrate/20250305233449_populate_type_source_in_reviewable.rb b/db/post_migrate/20250305233449_populate_type_source_in_reviewable.rb
new file mode 100644
index 00000000000..2af1f690dec
--- /dev/null
+++ b/db/post_migrate/20250305233449_populate_type_source_in_reviewable.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+class PopulateTypeSourceInReviewable < ActiveRecord::Migration[7.2]
+ def change
+ # Migrate known reviewables to have a type_source
+ # Copied from db/migrate/20250212045125_add_type_source_to_reviewable.rb
+ known_reviewables = {
+ "chat" => %w[ReviewableChatMessage],
+ "core" => %w[ReviewableFlaggedPost ReviewableQueuedPost ReviewableUser ReviewablePost],
+ "discourse-ai" => %w[ReviewableAiChatMessage ReviewableAiPost],
+ "discourse-akismet" => %w[
+ ReviewableAkismetPost
+ ReviewableAkismetPostVotingComment
+ ReviewableAkismetUser
+ ],
+ "discourse-antivirus" => %w[ReviewableUpload],
+ "discourse-category-experts" => %w[ReviewableCategoryExpertSuggestion],
+ "discourse-post-voting" => %w[ReviewablePostVotingComment],
+ }
+
+ known_reviewables.each do |plugin, types|
+ DB.exec(
+ "UPDATE reviewables SET type_source = :plugin WHERE type_source = 'unknown' AND type IN (:types)",
+ plugin: plugin,
+ types: types,
+ )
+ end
+ end
+end