From 4ad83a98a16804e49a5cdd44a3ccb04302c90cc2 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Mon, 11 Nov 2024 12:14:14 +1100 Subject: [PATCH] FIX: migrations must be finished to reset flags cache (#29693) Bug introduced here: https://github.com/discourse/discourse/pull/29609 It was checking if `flags` table existed before resetting the cache. However, `require_message` flag was added in further migration: https://github.com/discourse/discourse/blob/main/db/migrate/20240714231226_duplicate_flags_custom_type_to_require_message.rb#L5 When the admin tried to update Discourse which already has `flags` table but no `require_message` column, it was causing the error. Therefore, we should ensure that all migrations are finished before resetting flags cache. Meta: https://meta.discourse.org/t/update-failing-column-require-message-does-not-exist/335030 --- config/initializers/100-flags.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/initializers/100-flags.rb b/config/initializers/100-flags.rb index 4ba3954f0a4..17311b5190e 100644 --- a/config/initializers/100-flags.rb +++ b/config/initializers/100-flags.rb @@ -2,7 +2,8 @@ # On initialize, reset flags cache Rails.application.config.to_prepare do - if Discourse.cache.is_a?(Cache) && ActiveRecord::Base.connection.table_exists?(:flags) + if Discourse.cache.is_a?(Cache) && + !ActiveRecord::Base.connection.migration_context.needs_migration? Flag.reset_flag_settings! end end