summaryrefslogtreecommitdiff
path: root/db/migrate/20221206211814_add_authorized_scopes_to_slack_integration.rb
blob: 40abf087dfe6016b76a219150e046dc00514982f (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
# frozen_string_literal: true

class AddAuthorizedScopesToSlackIntegration < Gitlab::Database::Migration[2.1]
  def up
    create_table :slack_api_scopes do |t|
      t.text :name, null: false, limit: 100

      t.index :name, name: 'index_slack_api_scopes_on_name', unique: true
    end

    create_table :slack_integrations_scopes do |t|
      references :slack_api_scope,
        null: false,
        index: false, # See composite index
        foreign_key: {
          to_table: :slack_api_scopes,
          on_delete: :cascade
        }

      references :slack_integration,
        null: false,
        index: false, # see composite index
        foreign_key: {
          to_table: :slack_integrations,
          on_delete: :cascade
        }

      t.index [:slack_integration_id, :slack_api_scope_id],
        unique: true,
        name: 'index_slack_api_scopes_on_name_and_integration'
    end
  end

  def down
    drop_table :slack_integrations_scopes, if_exists: true
    drop_table :slack_api_scopes, if_exists: true
  end
end