Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20200515153633_iteration_date_range_constraint.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ab197ff8ae7189ca5da6223cd9646af60b94ce16 (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
36
37
38
39
# frozen_string_literal: true

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

  def up
    execute <<~SQL
      ALTER TABLE sprints
        ADD CONSTRAINT iteration_start_and_due_daterange_project_id_constraint
        EXCLUDE USING gist
        ( project_id WITH =,
          daterange(start_date, due_date, '[]') WITH &&
        )
        WHERE (project_id IS NOT NULL)
    SQL

    execute <<~SQL
      ALTER TABLE sprints
        ADD CONSTRAINT iteration_start_and_due_daterange_group_id_constraint
        EXCLUDE USING gist
        ( group_id WITH =,
          daterange(start_date, due_date, '[]') WITH &&
        )
        WHERE (group_id IS NOT NULL)
    SQL
  end

  def down
    execute <<~SQL
      ALTER TABLE sprints
        DROP CONSTRAINT IF EXISTS iteration_start_and_due_daterange_project_id_constraint
    SQL

    execute <<~SQL
      ALTER TABLE sprints
        DROP CONSTRAINT IF EXISTS iteration_start_and_due_daterange_group_id_constraint
    SQL
  end
end