DEV: Refactor seed data filter

Added a small helper class to for seed data because we need to add the
same filter to multisite:migrate as we have in db:migrate. Having this
filter in both places means we can get rid of the SKIP_SEED flag.
This commit is contained in:
Blake Erickson 2020-06-26 14:35:21 -06:00
parent 4efc126635
commit 69803599a9
1 changed files with 17 additions and 12 deletions

View File

@ -97,6 +97,18 @@ class StdOutDemux
end
end
class SeedHelper
def self.paths
DiscoursePluginRegistry.seed_paths
end
def self.filter
# Allows a plugin to exclude any specified seed data files from running
DiscoursePluginRegistry.seedfu_filter.any? ?
/^(?!.*(#{DiscoursePluginRegistry.seedfu_filter.to_a.join("|")})).*$/ : nil
end
end
task 'multisite:migrate' => ['db:load_config', 'environment', 'set_locale'] do |_, args|
if ENV["RAILS_ENV"] != "production"
raise "Multisite migrate is only supported in production"
@ -153,14 +165,12 @@ task 'multisite:migrate' => ['db:load_config', 'environment', 'set_locale'] do |
ActiveRecord::Tasks::DatabaseTasks.migrate
end
seed_paths = DiscoursePluginRegistry.seed_paths
SeedFu.seed(seed_paths, /001_refresh/)
SeedFu.seed(SeedHelper.paths, /001_refresh/)
execute_concurently(concurrency, exceptions) do |db|
if ENV['SKIP_SEED'] != '1'
puts "Seeding #{db}"
SeedFu.seed(seed_paths)
end
puts "Seeding #{db}"
SeedFu.seed(SeedHelper.paths, SeedHelper.filter)
if !Discourse.skip_post_deployment_migrations? && ENV['SKIP_OPTIMIZE_ICONS'] != '1'
SiteIconManager.ensure_optimized!
@ -203,12 +213,7 @@ task 'db:migrate' => ['load_config', 'environment', 'set_locale'] do |_, args|
end
SeedFu.quiet = true
# 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)
SeedFu.seed(SeedHelper.paths, SeedHelper.filter)
if !Discourse.skip_post_deployment_migrations? && ENV['SKIP_OPTIMIZE_ICONS'] != '1'
SiteIconManager.ensure_optimized!