summaryrefslogtreecommitdiff
path: root/db/post_migrate/20180502134117_migrate_import_attributes_data_from_projects_to_project_mirror_data.rb
blob: 08d7d64a2c551adb665e396c6fe1318a8e34f89b (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
class MigrateImportAttributesDataFromProjectsToProjectMirrorData < ActiveRecord::Migration
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  UP_MIGRATION = 'PopulateImportState'.freeze
  DOWN_MIGRATION = 'RollbackImportStateData'.freeze

  BATCH_SIZE = 1000
  DELAY_INTERVAL = 5.minutes

  disable_ddl_transaction!

  class Project < ActiveRecord::Base
    include EachBatch

    self.table_name = 'projects'
  end

  class ProjectImportState < ActiveRecord::Base
    include EachBatch

    self.table_name = 'project_mirror_data'
  end

  def up
    projects = Project.where.not(import_status: :none)

    queue_background_migration_jobs_by_range_at_intervals(projects, UP_MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE)
  end

  def down
    import_state = ProjectImportState.where.not(status: :none)

    queue_background_migration_jobs_by_range_at_intervals(import_state, DOWN_MIGRATION, DELAY_INTERVAL, batch_size: BATCH_SIZE)
  end
end