summaryrefslogtreecommitdiff
path: root/db/migrate/20210412111213_create_security_orchestration_policy_rule_schedule.rb
blob: c7035400cba9a21797c0aaf90b5d08522e6c8558 (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
# frozen_string_literal: true

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

  DOWNTIME = false
  INDEX_PREFIX = 'index_sop_schedules_'

  disable_ddl_transaction!

  def up
    table_comment = { owner: 'group::container security', description: 'Schedules used to store relationship between project and security policy repository' }

    create_table_with_constraints :security_orchestration_policy_rule_schedules, comment: table_comment.to_json do |t|
      t.timestamps_with_timezone
      t.datetime_with_timezone :next_run_at, null: true

      t.references :security_orchestration_policy_configuration, null: false, foreign_key: { to_table: :security_orchestration_policy_configurations, on_delete: :cascade }, index: { name: INDEX_PREFIX + 'on_sop_configuration_id' }
      t.references :user, null: false, foreign_key: { on_delete: :cascade }, index: { name: INDEX_PREFIX + 'on_user_id' }

      t.integer :policy_index, null: false
      t.text :cron, null: false

      t.text_limit :cron, 255
    end
  end

  def down
    with_lock_retries do
      drop_table :security_orchestration_policy_rule_schedules
    end
  end
end