From a2713578ddcf61b2e17abe064e3f367d472ed4f2 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Mon, 15 Jun 2020 15:28:07 -0600 Subject: [PATCH] DEV: Allow plugins to exclude seed data This allows plugins to specify if they would like to filter out any seed data files from running during migrations. --- lib/discourse_plugin_registry.rb | 5 +++++ lib/plugin/instance.rb | 8 ++++++++ lib/tasks/db.rake | 7 ++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/discourse_plugin_registry.rb b/lib/discourse_plugin_registry.rb index ab382a4d15c..73838496614 100644 --- a/lib/discourse_plugin_registry.rb +++ b/lib/discourse_plugin_registry.rb @@ -66,6 +66,7 @@ class DiscoursePluginRegistry define_register :seed_path_builders, Set define_register :vendored_pretty_text, Set define_register :vendored_core_pretty_text, Set + define_register :seedfu_filter, Set define_filtered_register :staff_user_custom_fields define_filtered_register :public_user_custom_fields @@ -198,6 +199,10 @@ class DiscoursePluginRegistry result.uniq end + def self.register_seedfu_filter(filter = nil) + self.seedfu_filter << filter + end + VENDORED_CORE_PRETTY_TEXT_MAP = { "moment.js" => "vendor/assets/javascripts/moment.js", "moment-timezone.js" => "vendor/assets/javascripts/moment-timezone-with-data.js" diff --git a/lib/plugin/instance.rb b/lib/plugin/instance.rb index 11f866f937c..302076e509b 100644 --- a/lib/plugin/instance.rb +++ b/lib/plugin/instance.rb @@ -78,6 +78,10 @@ class Plugin::Instance @seed_data ||= HashWithIndifferentAccess.new({}) end + def seed_fu_filter(filter = nil) + @seed_fu_filter = filter + end + def self.find_all(parent_path) [].tap { |plugins| # also follows symlinks - http://stackoverflow.com/q/357754 @@ -415,6 +419,10 @@ class Plugin::Instance SeedFu.fixture_paths.concat(paths) end + def register_seedfu_filter(filter = nil) + DiscoursePluginRegistry.register_seedfu_filter(filter) + end + def listen_for(event_name) return unless self.respond_to?(event_name) DiscourseEvent.on(event_name, &self.method(event_name)) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 5a6c67c9186..7b6c92806e9 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -180,7 +180,12 @@ task 'db:migrate' => ['load_config', 'environment', 'set_locale'] do |_, args| end SeedFu.quiet = true - SeedFu.seed(DiscoursePluginRegistry.seed_paths) + + # Allows a plugin to exclude any specified seed data files from running + filter = DiscoursePluginRegistry.seedfu_filter.any? ? + /^(?!.*(#{DiscoursePluginRegistry.seedfu_filter.to_a.join("|")})).*$/ : nil + + SeedFu.seed(DiscoursePluginRegistry.seed_paths, filter) if !Discourse.skip_post_deployment_migrations? && ENV['SKIP_OPTIMIZE_ICONS'] != '1' SiteIconManager.ensure_optimized!