From d57b7abe67adc654255d8061d5c2a9ec4543a102 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Wed, 6 Nov 2024 15:06:17 +1100 Subject: [PATCH] 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/e2292d4c5914875ad0e303770c56db7cc96847e3/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 --- config/initializers/100-flags.rb | 8 ++++++++ db/fixtures/003_flags.rb | 2 -- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 config/initializers/100-flags.rb diff --git a/config/initializers/100-flags.rb b/config/initializers/100-flags.rb new file mode 100644 index 00000000000..4ba3954f0a4 --- /dev/null +++ b/config/initializers/100-flags.rb @@ -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 diff --git a/db/fixtures/003_flags.rb b/db/fixtures/003_flags.rb index 008c01b31c0..b905f1fc7a1 100644 --- a/db/fixtures/003_flags.rb +++ b/db/fixtures/003_flags.rb @@ -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!