summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-08-02 15:31:39 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-08-11 18:15:02 +0200
commitf0f4506775d0e06b28ee55d591cb223115e3975a (patch)
tree3cc037b29ec0573df900ae1aefa02f50b4f5db6b
parent969ccec7bbaef3d55c3fc515de2b1d5335d6ae12 (diff)
downloadgitlab-ce-f0f4506775d0e06b28ee55d591cb223115e3975a.tar.gz
Don't update upload paths twice
This will be done in 20170717150329_enqueue_migrate_system_uploads_to_new_folder.rb instead.
-rw-r--r--db/post_migrate/20170317162059_update_upload_paths_to_system.rb57
-rw-r--r--spec/migrations/update_upload_paths_to_system_spec.rb53
2 files changed, 0 insertions, 110 deletions
diff --git a/db/post_migrate/20170317162059_update_upload_paths_to_system.rb b/db/post_migrate/20170317162059_update_upload_paths_to_system.rb
deleted file mode 100644
index ca2912f8dce..00000000000
--- a/db/post_migrate/20170317162059_update_upload_paths_to_system.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-# See http://doc.gitlab.com/ce/development/migration_style_guide.html
-# for more information on how to write migrations for GitLab.
-
-class UpdateUploadPathsToSystem < ActiveRecord::Migration
- include Gitlab::Database::MigrationHelpers
-
- DOWNTIME = false
- AFFECTED_MODELS = %w(User Project Note Namespace Appearance)
-
- disable_ddl_transaction!
-
- def up
- update_column_in_batches(:uploads, :path, replace_sql(arel_table[:path], base_directory, new_upload_dir)) do |_table, query|
- query.where(uploads_to_switch_to_new_path)
- end
- end
-
- def down
- update_column_in_batches(:uploads, :path, replace_sql(arel_table[:path], new_upload_dir, base_directory)) do |_table, query|
- query.where(uploads_to_switch_to_old_path)
- end
- end
-
- # "SELECT \"uploads\".* FROM \"uploads\" WHERE \"uploads\".\"model_type\" IN ('User', 'Project', 'Note', 'Namespace', 'Appearance') AND (\"uploads\".\"path\" ILIKE 'uploads/%' AND NOT (\"uploads\".\"path\" ILIKE 'uploads/system/%'))"
- def uploads_to_switch_to_new_path
- affected_uploads.and(starting_with_base_directory).and(starting_with_new_upload_directory.not)
- end
-
- # "SELECT \"uploads\".* FROM \"uploads\" WHERE \"uploads\".\"model_type\" IN ('User', 'Project', 'Note', 'Namespace', 'Appearance') AND (\"uploads\".\"path\" ILIKE 'uploads/%' AND \"uploads\".\"path\" ILIKE 'uploads/system/%')"
- def uploads_to_switch_to_old_path
- affected_uploads.and(starting_with_new_upload_directory)
- end
-
- def starting_with_base_directory
- arel_table[:path].matches("#{base_directory}/%")
- end
-
- def starting_with_new_upload_directory
- arel_table[:path].matches("#{new_upload_dir}/%")
- end
-
- def affected_uploads
- arel_table[:model_type].in(AFFECTED_MODELS)
- end
-
- def base_directory
- "uploads"
- end
-
- def new_upload_dir
- File.join(base_directory, "system")
- end
-
- def arel_table
- Arel::Table.new(:uploads)
- end
-end
diff --git a/spec/migrations/update_upload_paths_to_system_spec.rb b/spec/migrations/update_upload_paths_to_system_spec.rb
deleted file mode 100644
index 11412005b72..00000000000
--- a/spec/migrations/update_upload_paths_to_system_spec.rb
+++ /dev/null
@@ -1,53 +0,0 @@
-require "spec_helper"
-require Rails.root.join("db", "post_migrate", "20170317162059_update_upload_paths_to_system.rb")
-
-describe UpdateUploadPathsToSystem do
- let(:migration) { described_class.new }
-
- before do
- allow(migration).to receive(:say)
- end
-
- describe "#uploads_to_switch_to_new_path" do
- it "contains only uploads with the old path for the correct models" do
- _upload_for_other_type = create(:upload, model: create(:ci_pipeline), path: "uploads/ci_pipeline/avatar.jpg")
- _upload_with_system_path = create(:upload, model: create(:project), path: "uploads/system/project/avatar.jpg")
- _upload_with_other_path = create(:upload, model: create(:project), path: "thelongsecretforafileupload/avatar.jpg")
- old_upload = create(:upload, model: create(:project), path: "uploads/project/avatar.jpg")
- group_upload = create(:upload, model: create(:group), path: "uploads/group/avatar.jpg")
-
- expect(Upload.where(migration.uploads_to_switch_to_new_path)).to contain_exactly(old_upload, group_upload)
- end
- end
-
- describe "#uploads_to_switch_to_old_path" do
- it "contains only uploads with the new path for the correct models" do
- _upload_for_other_type = create(:upload, model: create(:ci_pipeline), path: "uploads/ci_pipeline/avatar.jpg")
- upload_with_system_path = create(:upload, model: create(:project), path: "uploads/system/project/avatar.jpg")
- _upload_with_other_path = create(:upload, model: create(:project), path: "thelongsecretforafileupload/avatar.jpg")
- _old_upload = create(:upload, model: create(:project), path: "uploads/project/avatar.jpg")
-
- expect(Upload.where(migration.uploads_to_switch_to_old_path)).to contain_exactly(upload_with_system_path)
- end
- end
-
- describe "#up", truncate: true do
- it "updates old upload records to the new path" do
- old_upload = create(:upload, model: create(:project), path: "uploads/project/avatar.jpg")
-
- migration.up
-
- expect(old_upload.reload.path).to eq("uploads/system/project/avatar.jpg")
- end
- end
-
- describe "#down", truncate: true do
- it "updates the new system patsh to the old paths" do
- new_upload = create(:upload, model: create(:project), path: "uploads/system/project/avatar.jpg")
-
- migration.down
-
- expect(new_upload.reload.path).to eq("uploads/project/avatar.jpg")
- end
- end
-end