From 69803599a96887c278522f5c98f69aea9520bc9f Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Fri, 26 Jun 2020 14:35:21 -0600 Subject: [PATCH] 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. --- lib/tasks/db.rake | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake index 88d6c353ce4..df929b1221f 100644 --- a/lib/tasks/db.rake +++ b/lib/tasks/db.rake @@ -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!