0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-05 13:42:12 +08:00
discourse/db/migrate/20200517140915_update_deprecated_icon_names.rb
Jarek Radosz 48691ee582
DEV: Enable Rails/FilePath rubocop rule (#40097)
(to be enabled in the shared config)
2026-05-19 19:07:54 +02:00

35 lines
775 B
Ruby
Vendored

# frozen_string_literal: true
class UpdateDeprecatedIconNames < ActiveRecord::Migration[6.0]
def up
migrate_value("up")
end
def down
migrate_value("down")
end
def migrate_value(dir)
icons =
File.open(
"#{Rails.root.join("db/migrate/20200517140915_fa4_renames.json")}",
"r:UTF-8",
) { |f| JSON.parse(f.read) }
icons.each do |key, value|
from = dir == "up" ? key : value
to = dir == "up" ? value : key
execute <<~SQL
UPDATE badges
SET icon = '#{to}'
WHERE icon = '#{from}' OR icon = 'fa-#{from}'
SQL
execute <<~SQL
UPDATE groups
SET flair_icon = '#{to}'
WHERE flair_icon = '#{from}' OR flair_icon = 'fa-#{from}'
SQL
end
end
end