summaryrefslogtreecommitdiff
path: root/db/migrate/20160902122721_drop_gitorious_field_from_application_settings.rb
blob: 6c2dc58876e410f25fa3db3f6e58ee7eb104aba4 (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
class DropGitoriousFieldFromApplicationSettings < ActiveRecord::Migration[4.2]
  include Gitlab::Database::MigrationHelpers

  # After the deploy the caches will be cold anyway
  DOWNTIME = false

  def up
    require 'yaml'

    import_sources = connection.execute('SELECT import_sources FROM application_settings;')
    return unless import_sources.first # support empty databases

    yaml = if Gitlab::Database.postgresql?
             import_sources.values[0][0]
           else
             import_sources.first[0]
           end

    yaml = YAML.safe_load(yaml)
    yaml.delete 'gitorious'

    # No need for a WHERE clause as there is only one
    connection.execute("UPDATE application_settings SET import_sources = #{update_yaml(yaml)}")
  end

  def down
    # noop, gitorious still yields a 404 anyway
  end

  private

  def connection
    ActiveRecord::Base.connection
  end

  def update_yaml(yaml)
    connection.quote(YAML.dump(yaml))
  end
end