UX: use "icon-picker" & "image-uploader" fields to set group flair. (#9779)

This commit is contained in:
Vinoth Kannan
2020-05-25 11:08:47 +05:30
committed by GitHub
parent 13d5ccedf5
commit 8e56197728
18 changed files with 270 additions and 35 deletions

View File

@@ -0,0 +1,36 @@
# frozen_string_literal: true
class AddMoreFlairColumnsToGroup < ActiveRecord::Migration[6.0]
def change
add_column :groups, :flair_icon, :string
add_column :groups, :flair_upload_id, :integer
reversible do |dir|
dir.up do
DB.exec(
<<~SQL
UPDATE groups SET flair_icon = REPLACE(REPLACE(flair_url, 'fas fa-', ''), ' fa-', '-')
WHERE flair_url LIKE 'fa%'
SQL
)
DB.exec(
<<~SQL
UPDATE groups g1
SET flair_upload_id = u.id
FROM groups g2
INNER JOIN uploads u ON g2.flair_url ~ CONCAT('\/', u.sha1, '[\.\w]*')
WHERE g1.id = g2.id
SQL
)
DB.exec(
<<~SQL
UPDATE groups SET flair_url = NULL
WHERE flair_icon IS NOT NULL OR flair_upload_id IS NOT NULL
SQL
)
end
end
end
end