mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:17:08 +08:00
35 lines
759 B
Ruby
35 lines
759 B
Ruby
# 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}/db/migrate/20200517140915_fa4_renames.json", "r:UTF-8") do |f|
|
|
JSON.parse(f.read)
|
|
end
|
|
|
|
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
|