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.
This commit is contained in:
Blake Erickson 2020-06-15 15:28:07 -06:00
parent a2f80670e1
commit a2713578dd
3 changed files with 19 additions and 1 deletions

View File

@ -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"

View File

@ -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))

View File

@ -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!