mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: Drop chat_uploads table and model and remove old references (#20926)
Followup to 0924f874bd9aca3515e17d0d084a35058e9d5757, we migrated Chat::Upload records to UploadReference records there and have not been making new Chat::Upload records for some time, we can now delete the model and table.
This commit is contained in:
@ -466,19 +466,13 @@ describe Chat::Message do
|
||||
expect { webhook_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it "destroys upload_references and chat_uploads" do
|
||||
it "destroys upload_references" do
|
||||
message_1 = Fabricate(:chat_message)
|
||||
upload_reference_1 = Fabricate(:upload_reference, target: message_1)
|
||||
upload_1 = Fabricate(:upload)
|
||||
# TODO (martin) Remove this when we remove ChatUpload completely, 2023-04-01
|
||||
DB.exec(<<~SQL)
|
||||
INSERT INTO chat_uploads(upload_id, chat_message_id, created_at, updated_at)
|
||||
VALUES(#{upload_1.id}, #{message_1.id}, NOW(), NOW())
|
||||
SQL
|
||||
|
||||
message_1.destroy!
|
||||
|
||||
expect(DB.query("SELECT * FROM chat_uploads WHERE upload_id = #{upload_1.id}")).to eq([])
|
||||
expect { upload_reference_1.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
@ -537,7 +531,6 @@ describe Chat::Message do
|
||||
it "creates an UploadReference record for the provided uploads" do
|
||||
chat_message.attach_uploads([upload_1, upload_2])
|
||||
upload_references = UploadReference.where(upload_id: [upload_1, upload_2])
|
||||
expect(chat_upload_count([upload_1, upload_2])).to eq(0)
|
||||
expect(upload_references.count).to eq(2)
|
||||
expect(upload_references.map(&:target_id).uniq).to eq([chat_message.id])
|
||||
expect(upload_references.map(&:target_type).uniq).to eq([Chat::Message.sti_name])
|
||||
@ -545,14 +538,12 @@ describe Chat::Message do
|
||||
|
||||
it "does nothing if the message record is new" do
|
||||
expect { described_class.new.attach_uploads([upload_1, upload_2]) }.to not_change {
|
||||
chat_upload_count
|
||||
}.and not_change { UploadReference.count }
|
||||
UploadReference.count
|
||||
}
|
||||
end
|
||||
|
||||
it "does nothing for an empty uploads array" do
|
||||
expect { chat_message.attach_uploads([]) }.to not_change {
|
||||
chat_upload_count
|
||||
}.and not_change { UploadReference.count }
|
||||
expect { chat_message.attach_uploads([]) }.to not_change { UploadReference.count }
|
||||
end
|
||||
end
|
||||
|
||||
@ -617,12 +608,4 @@ describe Chat::Message do
|
||||
expect(message.chat_mentions.pluck(:id)).to include(*existing_mention_ids) # the mentions weren't recreated
|
||||
end
|
||||
end
|
||||
|
||||
# TODO (martin) Remove this when we remove ChatUpload completely, 2023-04-01
|
||||
def chat_upload_count(uploads = nil)
|
||||
return DB.query_single("SELECT COUNT(*) FROM chat_uploads").first if !uploads
|
||||
DB.query_single(
|
||||
"SELECT COUNT(*) FROM chat_uploads WHERE upload_id IN (#{uploads.map(&:id).join(",")})",
|
||||
).first
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user