summaryrefslogtreecommitdiff
path: root/db/migrate/20200318140400_create_vulnerability_user_mentions.rb
blob: 919bc94cfa6eb00e5aa841395552a6f95cba8a35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

class CreateVulnerabilityUserMentions < ActiveRecord::Migration[6.0]
  DOWNTIME = false

  def change
    create_table :vulnerability_user_mentions do |t|
      t.references :vulnerability, type: :bigint, index: false, null: false, foreign_key: { on_delete: :cascade }
      t.references :note, type: :integer,
                   index: { where: 'note_id IS NOT NULL', unique: true }, null: true, foreign_key: { on_delete: :cascade }
      t.integer    :mentioned_users_ids, array: true
      t.integer    :mentioned_projects_ids, array: true
      t.integer    :mentioned_groups_ids, array: true
    end

    add_index :vulnerability_user_mentions, [:vulnerability_id], where: 'note_id is null', unique: true, name: 'index_vulns_user_mentions_on_vulnerability_id'
    add_index :vulnerability_user_mentions, [:vulnerability_id, :note_id], unique: true, name: 'index_vulns_user_mentions_on_vulnerability_id_and_note_id'
  end
end