summaryrefslogtreecommitdiff
path: root/db/post_migrate/20170807190736_move_personal_snippet_files_into_correct_folder.rb
blob: e3d2446b89787ca7451ea70ae78ee5cbce450dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.

class MovePersonalSnippetFilesIntoCorrectFolder < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers
  disable_ddl_transaction!

  DOWNTIME = false
  NEW_DIRECTORY = File.join('/uploads', '-', 'system', 'personal_snippet')
  OLD_DIRECTORY = File.join('/uploads', 'system', 'personal_snippet')

  def up
    return unless file_storage?

    BackgroundMigrationWorker.perform_async('MovePersonalSnippetFiles',
                                            [OLD_DIRECTORY, NEW_DIRECTORY])
  end

  def down
    return unless file_storage?

    BackgroundMigrationWorker.perform_async('MovePersonalSnippetFiles',
                                            [NEW_DIRECTORY, OLD_DIRECTORY])
  end

  def file_storage?
    CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File
  end
end