Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20210128172149_create_background_migration_tracking_tables.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 767bd8737a35c638b5feb29b5aa67fe98e061222 (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
# frozen_string_literal: true

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

  DOWNTIME = false

  def change
    create_table_with_constraints :batched_background_migrations do |t|
      t.timestamps_with_timezone
      t.bigint :min_value, null: false, default: 1
      t.bigint :max_value, null: false
      t.integer :batch_size, null: false
      t.integer :sub_batch_size, null: false
      t.integer :interval, limit: 2, null: false
      t.integer :status, limit: 2, null: false, default: 0
      t.text :job_class_name, null: false
      t.text :batch_class_name, null: false,
        default: 'Gitlab::Database::BackgroundMigration::PrimaryKeyBatchingStrategy'
      t.text :table_name, null: false
      t.text :column_name, null: false
      t.jsonb :job_arguments, null: false, default: '[]'

      t.text_limit :job_class_name, 100
      t.text_limit :batch_class_name, 100
      t.text_limit :table_name, 63
      t.text_limit :column_name, 63

      t.check_constraint :check_positive_min_value, 'min_value > 0'
      t.check_constraint :check_max_value_in_range, 'max_value >= min_value'

      t.check_constraint :check_positive_sub_batch_size, 'sub_batch_size > 0'
      t.check_constraint :check_batch_size_in_range, 'batch_size >= sub_batch_size'

      t.index %i[job_class_name table_name column_name], name: :index_batched_migrations_on_job_table_and_column_name
    end

    create_table :batched_background_migration_jobs do |t|
      t.timestamps_with_timezone
      t.datetime_with_timezone :started_at
      t.datetime_with_timezone :finished_at
      t.references :batched_background_migration, null: false, index: false, foreign_key: { on_delete: :cascade }
      t.bigint :min_value, null: false
      t.bigint :max_value, null: false
      t.integer :batch_size, null: false
      t.integer :sub_batch_size, null: false
      t.integer :status, limit: 2, null: false, default: 0
      t.integer :attempts, limit: 2, null: false, default: 0

      t.index [:batched_background_migration_id, :id], name: :index_batched_jobs_by_batched_migration_id_and_id
    end
  end

  def down
    drop_table :batched_background_migration_jobs

    drop_table :batched_background_migrations
  end
end