# frozen_string_literal: true

class CreateVulnerabilityOccurrenceIdentifiers < ActiveRecord::Migration[4.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  def change
    create_table :vulnerability_occurrence_identifiers, id: :bigserial do |t|
      t.timestamps_with_timezone null: false

      t.bigint :occurrence_id, null: false
      t.foreign_key :vulnerability_occurrences, column: :occurrence_id, on_delete: :cascade
      t.bigint :identifier_id, null: false
      t.foreign_key :vulnerability_identifiers, column: :identifier_id, on_delete: :cascade

      t.boolean :primary, null: false, default: false

      t.index :identifier_id
      t.index [:occurrence_id, :identifier_id],
        unique: true,
        name: 'index_vulnerability_occurrence_identifiers_on_unique_keys'
    end
  end
end
