summaryrefslogtreecommitdiff
path: root/db/migrate/20191120084627_add_encrypted_fields_to_application_settings.rb
blob: 7bb2d9c63016f3ab2cb0389ef25c2dc53f990a86 (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
# frozen_string_literal: true

class AddEncryptedFieldsToApplicationSettings < ActiveRecord::Migration[5.2]
  include Gitlab::Database::MigrationHelpers

  DOWNTIME = false

  PLAINTEXT_ATTRIBUTES = %w[
    akismet_api_key
    elasticsearch_aws_secret_access_key
    recaptcha_private_key
    recaptcha_site_key
    slack_app_secret
    slack_app_verification_token
  ].freeze

  # rubocop:disable Migration/PreventStrings
  # rubocop:disable Migration/AddLimitToTextColumns
  def up
    PLAINTEXT_ATTRIBUTES.each do |plaintext_attribute|
      add_column :application_settings, "encrypted_#{plaintext_attribute}", :text
      add_column :application_settings, "encrypted_#{plaintext_attribute}_iv", :string, limit: 255
    end
  end
  # rubocop:enable Migration/AddLimitToTextColumns
  # rubocop:enable Migration/PreventStrings

  def down
    PLAINTEXT_ATTRIBUTES.each do |plaintext_attribute|
      remove_column :application_settings, "encrypted_#{plaintext_attribute}"
      remove_column :application_settings, "encrypted_#{plaintext_attribute}_iv"
    end
  end
end