mirror of
https://github.com/discourse/discourse.git
synced 2026-08-05 21:57:36 +08:00
35 lines
775 B
Ruby
Vendored
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
|