FIX: setup with db:create db:migrate (#29609)

After data seed, we should reset Redis cache to ensure that the correct flags are cached.

However, `db:create` is skipping Redis 

https://github.com/discourse/discourse/blob/main/lib/tasks/db.rake#L39

And uses `ActiveSupport::Cache::MemoryStore.new`

https://github.com/discourse/discourse/blob/a96c11d45b5dcaf0d5ddef846c60f7b7f28b8112/lib/discourse.rb#L523

Therefore, the reset flags cache was moved to initializers and evaluated only when the cache is Redis and Flags table already exists.

Meta: https://meta.discourse.org/t/development-install-fails-when-running-bin-rails-db-migrate/332754
This commit is contained in:
Krzysztof Kotlarek
2024-11-06 15:06:17 +11:00
committed by GitHub
parent 26a2fa8182
commit e38e219a68
2 changed files with 8 additions and 2 deletions
+8
View File
@@ -0,0 +1,8 @@
# frozen_string_literal: true
# On initialize, reset flags cache
Rails.application.config.to_prepare do
if Discourse.cache.is_a?(Cache) && ActiveRecord::Base.connection.table_exists?(:flags)
Flag.reset_flag_settings!
end
end
-2
View File
@@ -74,5 +74,3 @@ Flag.unscoped.seed do |s|
s.applies_to = %w[Post]
s.skip_reset_flag_callback = true
end
Flag.reset_flag_settings!