mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
Currently the process of adding a custom image to badge is quite clunky; you have to upload your image to a topic, and then copy the image URL and pasting it in a text field. Besides being clucky, if the topic or post that contains the image is deleted, the image will be garbage-collected in a few days and the badge will lose the image because the application is not that the image is referenced by a badge. This commit improves that by adding a proper image uploader widget for badge images.
20 lines
464 B
Ruby
20 lines
464 B
Ruby
# frozen_string_literal: true
|
|
|
|
class AddImageUploadIdToBadges < ActiveRecord::Migration[6.0]
|
|
def change
|
|
add_column :badges, :image_upload_id, :integer
|
|
reversible do |dir|
|
|
dir.up do
|
|
DB.exec <<~SQL
|
|
UPDATE badges b1
|
|
SET image_upload_id = u.id
|
|
FROM badges b2
|
|
INNER JOIN uploads u
|
|
ON b2.image ~ CONCAT('/', u.sha1, '\\.\\w')
|
|
WHERE b1.id = b2.id
|
|
SQL
|
|
end
|
|
end
|
|
end
|
|
end
|