FIX: `Upload#migrate_to_new_scheme` should not migrate system uploads.

FIX: Upload#migrate_to_new_scheme should not migrate system uploads.

diff --git a/app/models/upload.rb b/app/models/upload.rb
index 262d0e2..4a53823 100644
--- a/app/models/upload.rb
+++ b/app/models/upload.rb
@@ -224,7 +224,10 @@ class Upload < ActiveRecord::Base
       max_file_size_kb = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes
       local_store =
-      scope = Upload.where("url NOT LIKE '%/original/_X/%'").order(id: :desc)
+      scope = Upload.by_users
+        .where("url NOT LIKE '%/original/_X/%'")
+        .order(id: :desc)
       scope = scope.limit(limit) if limit
       scope.each do |upload|
diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb
index 95ed94f..59fa7e4 100644
--- a/spec/models/upload_spec.rb
+++ b/spec/models/upload_spec.rb
@@ -250,4 +250,13 @@ describe Upload do
+  describe '.migrate_to_new_scheme' do
+    it 'should not migrate system uploads' do
+      SiteSetting.migrate_to_new_scheme = true
+      expect { Upload.migrate_to_new_scheme }
+        .to_not change { Upload.pluck(:url) }
+    end
+  end

GitHub sha: 40b03e71

@SamSaffron I’m very tempted to add a default scope to uploads here. I don’t think we need to unscope from uploads often.

hmmm as in one that excludes system uploads? I would be open to a default scope here if we soft deleted, but excluding certain uploads that are good seems a bit overkill.

O yea just excluding system uploads because the URL follows a different scheme than normal uploads.