summaryrefslogtreecommitdiff
path: root/db/post_migrate/20191021101942_remove_empty_github_service_templates.rb
blob: 64abe93b3e819113b13c5376a46243870f1d4908 (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
# frozen_string_literal: true

## It's expected to delete one record on GitLab.com
#
class RemoveEmptyGithubServiceTemplates < ActiveRecord::Migration[5.2]
  DOWNTIME = false

  class Service < ActiveRecord::Base
    self.table_name = 'services'
    self.inheritance_column = :_type_disabled

    serialize :properties, JSON
  end

  def up
    relationship.where(properties: {}).delete_all
  end

  def down
    relationship.find_or_create_by!(properties: {})
  end

  private

  def relationship
    RemoveEmptyGithubServiceTemplates::Service.where(template: true, type: 'GithubService')
  end
end