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:
Martin Brennan
2023-04-04 09:13:39 +10:00
committed by GitHub
parent 858b1ccc51
commit c00d17535f
10 changed files with 29 additions and 144 deletions

View File

@ -813,9 +813,7 @@ describe Chat::MessageCreator do
content: "Beep boop",
upload_ids: [upload1.id],
)
}.to not_change { chat_upload_count([upload1]) }.and change {
UploadReference.where(upload_id: upload1.id).count
}.by(1)
}.to change { UploadReference.where(upload_id: upload1.id).count }.by(1)
end
it "can attach multiple uploads to a new message" do
@ -826,9 +824,7 @@ describe Chat::MessageCreator do
content: "Beep boop",
upload_ids: [upload1.id, upload2.id],
)
}.to not_change { chat_upload_count([upload1, upload2]) }.and change {
UploadReference.where(upload_id: [upload1.id, upload2.id]).count
}.by(2)
}.to change { UploadReference.where(upload_id: [upload1.id, upload2.id]).count }.by(2)
end
it "filters out uploads that weren't uploaded by the user" do
@ -839,7 +835,7 @@ describe Chat::MessageCreator do
content: "Beep boop",
upload_ids: [private_upload.id],
)
}.not_to change { chat_upload_count([private_upload]) }
}.not_to change { UploadReference.where(upload_id: private_upload.id).count }
end
it "doesn't attach uploads when `chat_allow_uploads` is false" do
@ -851,9 +847,7 @@ describe Chat::MessageCreator do
content: "Beep boop",
upload_ids: [upload1.id],
)
}.to not_change { chat_upload_count([upload1]) }.and not_change {
UploadReference.where(upload_id: upload1.id).count
}
}.to not_change { UploadReference.where(upload_id: upload1.id).count }
end
end
end
@ -942,11 +936,4 @@ describe Chat::MessageCreator do
end
end
end
# TODO (martin) Remove this when we remove ChatUpload completely, 2023-04-01
def chat_upload_count(uploads)
DB.query_single(
"SELECT COUNT(*) FROM chat_uploads WHERE upload_id IN (#{uploads.map(&:id).join(",")})",
).first
end
end

View File

@ -332,7 +332,7 @@ describe Chat::MessageUpdater do
new_content: "I guess this is different",
upload_ids: [upload2.id, upload1.id],
)
}.to not_change { chat_upload_count }.and not_change { UploadReference.count }
}.to not_change { UploadReference.count }
end
it "removes uploads that should be removed" do
@ -344,15 +344,6 @@ describe Chat::MessageUpdater do
upload_ids: [upload1.id, upload2.id],
)
# 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(#{upload1.id}, #{chat_message.id}, NOW(), NOW())
SQL
DB.exec(<<~SQL)
INSERT INTO chat_uploads(upload_id, chat_message_id, created_at, updated_at)
VALUES(#{upload2.id}, #{chat_message.id}, NOW(), NOW())
SQL
expect {
Chat::MessageUpdater.update(
guardian: guardian,
@ -360,9 +351,7 @@ describe Chat::MessageUpdater do
new_content: "I guess this is different",
upload_ids: [upload1.id],
)
}.to change { chat_upload_count([upload2]) }.by(-1).and change {
UploadReference.where(upload_id: upload2.id).count
}.by(-1)
}.to change { UploadReference.where(upload_id: upload2.id).count }.by(-1)
end
it "removes all uploads if they should be removed" do
@ -374,15 +363,6 @@ describe Chat::MessageUpdater do
upload_ids: [upload1.id, upload2.id],
)
# 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(#{upload1.id}, #{chat_message.id}, NOW(), NOW())
SQL
DB.exec(<<~SQL)
INSERT INTO chat_uploads(upload_id, chat_message_id, created_at, updated_at)
VALUES(#{upload2.id}, #{chat_message.id}, NOW(), NOW())
SQL
expect {
Chat::MessageUpdater.update(
guardian: guardian,
@ -390,9 +370,7 @@ describe Chat::MessageUpdater do
new_content: "I guess this is different",
upload_ids: [],
)
}.to change { chat_upload_count([upload1, upload2]) }.by(-2).and change {
UploadReference.where(target: chat_message).count
}.by(-2)
}.to change { UploadReference.where(target: chat_message).count }.by(-2)
end
it "adds one upload if none exist" do
@ -404,9 +382,7 @@ describe Chat::MessageUpdater do
new_content: "I guess this is different",
upload_ids: [upload1.id],
)
}.to not_change { chat_upload_count([upload1]) }.and change {
UploadReference.where(target: chat_message).count
}.by(1)
}.to change { UploadReference.where(target: chat_message).count }.by(1)
end
it "adds multiple uploads if none exist" do
@ -418,9 +394,7 @@ describe Chat::MessageUpdater do
new_content: "I guess this is different",
upload_ids: [upload1.id, upload2.id],
)
}.to not_change { chat_upload_count([upload1, upload2]) }.and change {
UploadReference.where(target: chat_message).count
}.by(2)
}.to change { UploadReference.where(target: chat_message).count }.by(2)
end
it "doesn't remove existing uploads when upload ids that do not exist are passed in" do
@ -433,9 +407,7 @@ describe Chat::MessageUpdater do
new_content: "I guess this is different",
upload_ids: [0],
)
}.to not_change { chat_upload_count }.and not_change {
UploadReference.where(target: chat_message).count
}
}.to not_change { UploadReference.where(target: chat_message).count }
end
it "doesn't add uploads if `chat_allow_uploads` is false" do
@ -448,9 +420,7 @@ describe Chat::MessageUpdater do
new_content: "I guess this is different",
upload_ids: [upload1.id, upload2.id],
)
}.to not_change { chat_upload_count([upload1, upload2]) }.and not_change {
UploadReference.where(target: chat_message).count
}
}.to not_change { UploadReference.where(target: chat_message).count }
end
it "doesn't remove existing uploads if `chat_allow_uploads` is false" do
@ -469,9 +439,7 @@ describe Chat::MessageUpdater do
new_content: "I guess this is different",
upload_ids: [],
)
}.to not_change { chat_upload_count }.and not_change {
UploadReference.where(target: chat_message).count
}
}.to not_change { UploadReference.where(target: chat_message).count }
end
it "updates if upload is present even if length is less than `chat_minimum_message_length`" do
@ -575,12 +543,4 @@ describe Chat::MessageUpdater do
end
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