summaryrefslogtreecommitdiff
path: root/db/migrate/20200928203531_create_alert_management_http_integrations.rb
blob: fe13fe400e3c01a234dfcd0e561a56bfe96fda05 (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
# frozen_string_literal: true

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

  DOWNTIME = false
  UNIQUE_INDEX = 'index_http_integrations_on_active_and_project_and_endpoint'

  disable_ddl_transaction!

  def up
    create_table :alert_management_http_integrations, if_not_exists: true do |t|
      t.timestamps_with_timezone
      t.bigint :project_id, index: true, null: false
      t.boolean :active, null: false, default: false
      t.text :encrypted_token, null: false
      t.text :encrypted_token_iv, null: false
      t.text :endpoint_identifier, null: false
      t.text :name, null: false
    end

    add_text_limit :alert_management_http_integrations, :encrypted_token, 255
    add_text_limit :alert_management_http_integrations, :encrypted_token_iv, 255
    add_text_limit :alert_management_http_integrations, :endpoint_identifier, 255
    add_text_limit :alert_management_http_integrations, :name, 255

    add_index :alert_management_http_integrations,
              [:active, :project_id, :endpoint_identifier],
              unique: true,
              name: UNIQUE_INDEX,
              where: 'active'
  end

  def down
    drop_table :alert_management_http_integrations
  end
end