FIX: Use a mutex when reseting column information while seeding.

FIX: Use a mutex when reseting column information while seeding.

rake multisite:migrate runs SeedFu concurently in threads so we need this to be thread safe.

diff --git a/db/fixtures/001_refresh.rb b/db/fixtures/001_refresh.rb
index e340c8d..5147896 100644
--- a/db/fixtures/001_refresh.rb
+++ b/db/fixtures/001_refresh.rb
@@ -1,17 +1,22 @@
 # frozen_string_literal: true
 
 class SeedData::Refresher
+  @mutex = Mutex.new
+
   def self.refresh!
     return if @refreshed
 
-    # Fix any bust caches post initial migration
-    # Not that reset_column_information is not thread safe so we have to becareful
-    # not to run it concurrently within the same process.
-    ActiveRecord::Base.connection.tables.each do |table|
-      table.classify.constantize.reset_column_information rescue nil
-    end
+    @mutex.synchronize do
+      return if @refreshed
+      # Fix any bust caches post initial migration
+      # Not that reset_column_information is not thread safe so we have to becareful
+      # not to run it concurrently within the same process.
+      ActiveRecord::Base.connection.tables.each do |table|
+        table.classify.constantize.reset_column_information rescue nil
+      end
 
-    @refreshed = true
+      @refreshed = true
+    end
   end
 end
 

GitHub sha: d775338d