summaryrefslogtreecommitdiff
path: root/db/migrate/20200607223047_create_cluster_agents.rb
blob: 50dd28562e4e8c5ac1ceab7e33f8ebbb006372da (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
# frozen_string_literal: true

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

  DOWNTIME = false

  disable_ddl_transaction!

  def up
    unless table_exists?(:cluster_agents)
      with_lock_retries do
        create_table :cluster_agents do |t|
          t.timestamps_with_timezone null: false
          t.belongs_to(:project, null: false, index: true, foreign_key: { on_delete: :cascade })
          t.text :name, null: false

          t.index [:project_id, :name], unique: true
        end
      end
    end

    add_text_limit :cluster_agents, :name, 255
  end

  def down
    with_lock_retries do
      drop_table :cluster_agents
    end
  end
end