summaryrefslogtreecommitdiff
path: root/db/migrate/20160119111158_add_services_category.rb
blob: 979a48584a935f386b5b8ee3ce88658404ee91a5 (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
40
# rubocop:disable all
class AddServicesCategory < ActiveRecord::Migration[4.2]
  def up
    add_column :services, :category, :string, default: 'common', null: false

    category = quote_column_name('category')
    type     = quote_column_name('type')

    execute <<-EOF
UPDATE services
SET #{category} = 'issue_tracker'
WHERE #{type} IN (
  'CustomIssueTrackerService',
  'GitlabIssueTrackerService',
  'IssueTrackerService',
  'JiraService',
  'RedmineService'
);
EOF

    execute <<-EOF
UPDATE services
SET #{category} = 'ci'
WHERE #{type} IN (
  'BambooService',
  'BuildkiteService',
  'CiService',
  'DroneCiService',
  'GitlabCiService',
  'TeamcityService'
);
    EOF

    add_index :services, :category
  end

  def down
    remove_column :services, :category
  end
end