PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/db/post_migrate/20170606202615_move_appearance_to_system_dir.rb

https://gitlab.com/visay/gitlab-ce
Ruby | 57 lines | 44 code | 13 blank | 0 comment | 2 complexity | 82d072ca726e47c5d2e9373993afda68 MD5 | raw file
 1class MoveAppearanceToSystemDir < ActiveRecord::Migration
 2  include Gitlab::Database::MigrationHelpers
 3  disable_ddl_transaction!
 4
 5  DOWNTIME = false
 6  DIRECTORY_TO_MOVE = 'appearance'.freeze
 7
 8  def up
 9    source = File.join(old_upload_dir, DIRECTORY_TO_MOVE)
10    destination = File.join(new_upload_dir, DIRECTORY_TO_MOVE)
11
12    move_directory(source, destination)
13  end
14
15  def down
16    source = File.join(new_upload_dir, DIRECTORY_TO_MOVE)
17    destination = File.join(old_upload_dir, DIRECTORY_TO_MOVE)
18
19    move_directory(source, destination)
20  end
21
22  def move_directory(source, destination)
23    unless file_storage?
24      say 'Not using file storage, skipping'
25      return
26    end
27
28    unless File.directory?(source)
29      say "#{source} did not exist, skipping"
30      return
31    end
32
33    if File.directory?(destination)
34      say "#{destination} already existed, skipping"
35      return
36    end
37
38    say "Moving #{source} -> #{destination}"
39    FileUtils.mv(source, destination)
40  end
41
42  def file_storage?
43    CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File
44  end
45
46  def base_directory
47    Rails.root
48  end
49
50  def old_upload_dir
51    File.join(base_directory, "public", "uploads")
52  end
53
54  def new_upload_dir
55    File.join(base_directory, "public", "uploads", "system")
56  end
57end