summaryrefslogtreecommitdiff
path: root/db/migrate/20200624142107_create_analytics_cycle_analytics_group_value_streams.rb
blob: 24afe4636844615fbdf68538059a41bc0e3792c5 (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 CreateAnalyticsCycleAnalyticsGroupValueStreams < ActiveRecord::Migration[6.0]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false
  INDEX_NAME = 'index_analytics_ca_group_value_streams_on_group_id_and_name'

  disable_ddl_transaction!

  def up
    unless table_exists?(:analytics_cycle_analytics_group_value_streams)
      with_lock_retries do
        create_table :analytics_cycle_analytics_group_value_streams do |t|
          t.timestamps_with_timezone
          t.references(:group, {
            null: false,
            index: false,
            foreign_key: { to_table: :namespaces, on_delete: :cascade }
          })
          t.text :name, null: false
          t.index [:group_id, :name], unique: true, name: INDEX_NAME
        end
      end
    end

    add_text_limit :analytics_cycle_analytics_group_value_streams, :name, 100
  end

  def down
    drop_table :analytics_cycle_analytics_group_value_streams
  end
end