summaryrefslogtreecommitdiff
path: root/db/migrate/20191003300045_create_snippet_user_mentions.rb
blob: fb7681d6e33961fe89fb7e9940d3447ad37d08f6 (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 CreateSnippetUserMentions < ActiveRecord::Migration[5.2]
  DOWNTIME = false

  def change
    create_table :snippet_user_mentions do |t|
      t.references :snippet, type: :integer, 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 :snippet_user_mentions, [:snippet_id], where: 'note_id is null', unique: true, name: 'snippet_user_mentions_on_snippet_id_index'
    add_index :snippet_user_mentions, [:snippet_id, :note_id], unique: true, name: 'snippet_user_mentions_on_snippet_id_and_note_id_index'
  end
end