summaryrefslogtreecommitdiff
path: root/db/post_migrate/20180424151928_fill_file_store.rb
blob: 45fa10c955007f68395e7cff709c41d45cd724c8 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class FillFileStore < ActiveRecord::Migration[4.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  disable_ddl_transaction!

  class JobArtifact < ActiveRecord::Base
    include EachBatch
    self.table_name = 'ci_job_artifacts'
    BATCH_SIZE = 10_000

    def self.params_for_background_migration
      yield self.where(file_store: nil), 'FillFileStoreJobArtifact', 5.minutes, BATCH_SIZE
    end
  end

  class LfsObject < ActiveRecord::Base
    include EachBatch
    self.table_name = 'lfs_objects'
    BATCH_SIZE = 10_000

    def self.params_for_background_migration
      yield self.where(file_store: nil), 'FillFileStoreLfsObject', 5.minutes, BATCH_SIZE
    end
  end

  class Upload < ActiveRecord::Base
    include EachBatch
    self.table_name = 'uploads'
    self.inheritance_column = :_type_disabled # Disable STI
    BATCH_SIZE = 10_000

    def self.params_for_background_migration
      yield self.where(store: nil), 'FillStoreUpload', 5.minutes, BATCH_SIZE
    end
  end

  def up
    # NOTE: Schedule background migrations that fill 'NULL' value by '1'(ObjectStorage::Store::LOCAL) on `file_store`, `store` columns
    #
    # Here are the target columns
    # - ci_job_artifacts.file_store
    # - lfs_objects.file_store
    # - uploads.store

    FillFileStore::JobArtifact.params_for_background_migration do |relation, class_name, delay_interval, batch_size|
      queue_background_migration_jobs_by_range_at_intervals(relation,
        class_name,
        delay_interval,
        batch_size: batch_size)
    end

    FillFileStore::LfsObject.params_for_background_migration do |relation, class_name, delay_interval, batch_size|
      queue_background_migration_jobs_by_range_at_intervals(relation,
        class_name,
        delay_interval,
        batch_size: batch_size)
    end

    FillFileStore::Upload.params_for_background_migration do |relation, class_name, delay_interval, batch_size|
      queue_background_migration_jobs_by_range_at_intervals(relation,
        class_name,
        delay_interval,
        batch_size: batch_size)
    end
  end

  def down
    # noop
  end
end