summaryrefslogtreecommitdiff
path: root/db/migrate/20200213224220_add_sprints.rb
blob: 8d82d1e261aa76d9ec24fd6dfc0a01fdff7da357 (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
34
35
# frozen_string_literal: true

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

  def change
    create_table :sprints, id: :bigserial do |t|
      t.timestamps_with_timezone null: false
      t.date :start_date
      t.date :due_date

      t.references :project, foreign_key: false, index: false
      t.references :group, foreign_key: false, index: true

      t.integer :iid, null: false
      t.integer :cached_markdown_version
      t.integer :state, limit: 2
      # rubocop:disable Migration/AddLimitToTextColumns
      t.text :title, null: false
      t.text :title_html
      t.text :description
      t.text :description_html
      # rubocop:enable Migration/AddLimitToTextColumns

      t.index :description, name: "index_sprints_on_description_trigram", opclass: :gin_trgm_ops, using: :gin
      t.index :due_date
      t.index %w(project_id iid), unique: true
      t.index :title
      t.index :title, name: "index_sprints_on_title_trigram", opclass: :gin_trgm_ops, using: :gin

      t.index %w(project_id title), unique: true, where: 'project_id IS NOT NULL'
      t.index %w(group_id title), unique: true, where: 'group_id IS NOT NULL'
    end
  end
end