DEV: add migration to remap from deprecated icon names for badges (#30983)

This is a very narrowly scoped migration to update badges.icon for two
deprecated names `smile` and `share-alt`. Following on from this PR that
updated the Badge seed fixture used as part of site creation:
https://github.com/discourse/discourse/pull/30942

The migration logic closely follows that of the [previous DB
migrations](https://github.com/discourse/discourse/pull/30100) that
updated all deprecated FA icon names, just that we reduce the mappings
to only look for `smile` and `share-alt`.
This commit is contained in:
Kelv
2025-01-24 15:26:39 +08:00
committed by GitHub
parent 62c6ee0de7
commit 71a9e9f598

View File

@ -0,0 +1,21 @@
# frozen_string_literal: true
#
class RemapDeprecatedIconNamesForSeededBadges < ActiveRecord::Migration[7.2]
def up
execute <<~SQL
WITH remaps AS (
SELECT from_icon, to_icon
FROM (VALUES ('smile', 'face-smile'), ('share-alt', 'share-nodes'))
AS mapping(from_icon, to_icon)
)
UPDATE badges
SET icon = remaps.to_icon
FROM remaps
WHERE icon = remaps.from_icon;
SQL
end
def down
raise ActiveRecord::IrreversibleMigration
end
end