DEV: ignore `flair_url` column in group model. (#9873)
This commit is contained in:
parent
8825395bdc
commit
5fb9271878
|
@ -4,11 +4,20 @@ require 'uri'
|
||||||
module Jobs
|
module Jobs
|
||||||
class MigrateGroupFlairImages < ::Jobs::Onceoff
|
class MigrateGroupFlairImages < ::Jobs::Onceoff
|
||||||
def execute_onceoff(args)
|
def execute_onceoff(args)
|
||||||
return if Group.column_names.exclude?("flair_url")
|
column_exists = DB.exec(<<~SQL) == 1
|
||||||
|
SELECT 1
|
||||||
|
FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE
|
||||||
|
table_schema = 'public' AND
|
||||||
|
table_name = 'groups' AND
|
||||||
|
column_name = 'flair_url'
|
||||||
|
SQL
|
||||||
|
return unless column_exists
|
||||||
|
|
||||||
Group.where.not(flair_url: nil).each do |group|
|
groups = Group.where.not(flair_url: nil).select(:id, :flair_url, :flair_upload_id, :name)
|
||||||
|
groups.each do |group|
|
||||||
if group.flair_upload.present?
|
if group.flair_upload.present?
|
||||||
g.update_column(:flair_url, nil)
|
DB.exec("UPDATE groups SET flair_url = NULL WHERE id = #{group.id}")
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -68,7 +77,7 @@ module Jobs
|
||||||
origin: UrlHelper.absolute(old_url)
|
origin: UrlHelper.absolute(old_url)
|
||||||
).create_for(Discourse.system_user.id)
|
).create_for(Discourse.system_user.id)
|
||||||
|
|
||||||
group.update_columns(flair_upload_id: upload.id, flair_url: nil) if upload.present?
|
DB.exec("UPDATE groups SET flair_url = NULL, flair_upload_id = #{upload.id} WHERE id = #{group.id}") if upload.present?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class Group < ActiveRecord::Base
|
class Group < ActiveRecord::Base
|
||||||
# TODO(2021-04-22): remove
|
# TODO(2021-05-26): remove
|
||||||
self.ignored_columns = %w{
|
self.ignored_columns = %w{
|
||||||
automatic_membership_retroactive
|
automatic_membership_retroactive
|
||||||
|
flair_url
|
||||||
}
|
}
|
||||||
|
|
||||||
include HasCustomFields
|
include HasCustomFields
|
||||||
|
|
|
@ -4,6 +4,7 @@ require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe Jobs::MigrateGroupFlairImages do
|
RSpec.describe Jobs::MigrateGroupFlairImages do
|
||||||
let(:image_url) { "https://omg.aws.somestack/test.png" }
|
let(:image_url) { "https://omg.aws.somestack/test.png" }
|
||||||
|
let(:group) { Fabricate(:group) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
stub_request(:get, image_url).to_return(
|
stub_request(:get, image_url).to_return(
|
||||||
|
@ -18,7 +19,9 @@ RSpec.describe Jobs::MigrateGroupFlairImages do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should migrate to the new group `flair_upload_id` column correctly' do
|
it 'should migrate to the new group `flair_upload_id` column correctly' do
|
||||||
group = Fabricate(:group, flair_url: image_url)
|
DB.exec(<<~SQL, flair_url: image_url)
|
||||||
|
UPDATE groups SET flair_url = :flair_url WHERE id = #{group.id}
|
||||||
|
SQL
|
||||||
|
|
||||||
expect do
|
expect do
|
||||||
described_class.new.execute_onceoff({})
|
described_class.new.execute_onceoff({})
|
||||||
|
@ -30,7 +33,7 @@ RSpec.describe Jobs::MigrateGroupFlairImages do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should skip groups with invalid flair URLs' do
|
it 'should skip groups with invalid flair URLs' do
|
||||||
group = Fabricate(:group, flair_url: "abc")
|
DB.exec("UPDATE groups SET flair_url = 'abc' WHERE id = #{group.id}")
|
||||||
described_class.new.execute_onceoff({})
|
described_class.new.execute_onceoff({})
|
||||||
expect(Rails.logger.warnings.count).to eq(0)
|
expect(Rails.logger.warnings.count).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue