summaryrefslogtreecommitdiff
path: root/db/migrate/20210527194558_create_ci_job_token_project_scope_links.rb
blob: aaa94b9a231034cf284e814f2bf15856bafb7c39 (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
# frozen_string_literal: true

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

  def up
    with_lock_retries do
      create_table :ci_job_token_project_scope_links, if_not_exists: true do |t|
        t.belongs_to :source_project, index: false, null: false, foreign_key: { to_table: :projects, on_delete: :cascade }
        t.belongs_to :target_project, null: false, foreign_key: { to_table: :projects, on_delete: :cascade }
        t.belongs_to :added_by, foreign_key: { to_table: :users, on_delete: :nullify }
        t.datetime_with_timezone :created_at, null: false

        t.index [:source_project_id, :target_project_id], unique: true, name: 'i_ci_job_token_project_scope_links_on_source_and_target_project'
      end
    end
  end

  def down
    with_lock_retries do
      drop_table :ci_job_token_project_scope_links, if_exists: true
    end
  end
end