summaryrefslogtreecommitdiff
path: root/db/post_migrate/20210302150310_schedule_migrate_pages_to_zip_storage.rb
blob: 7f6d7ffe9b7d7d1bcec2ec54d0ce3b10fed56436 (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
# frozen_string_literal: true

class ScheduleMigratePagesToZipStorage < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  MIGRATION = 'MigratePagesToZipStorage'
  BATCH_SIZE = 10
  BATCH_TIME = 5.minutes

  disable_ddl_transaction!

  class ProjectPagesMetadatum < ActiveRecord::Base
    extend SuppressCompositePrimaryKeyWarning

    include EachBatch

    self.primary_key = :project_id
    self.table_name = 'project_pages_metadata'
    self.inheritance_column = :_type_disabled

    scope :deployed, -> { where(deployed: true) }
    scope :only_on_legacy_storage, -> { deployed.where(pages_deployment_id: nil) }
  end

  def up
    queue_background_migration_jobs_by_range_at_intervals(
      ProjectPagesMetadatum.only_on_legacy_storage,
      MIGRATION,
      BATCH_TIME,
      batch_size: BATCH_SIZE,
      primary_column_name: :project_id
    )
  end
end