최대 업로드 50위 목록 스크립트 오류

가끔 탐색기 스크립트를 사용해 큰 용량의 업로드를 찾습니다.

쿼리를 실행하려고 하면

SELECT posts.id AS post_id,
    uploads.original_filename,
    ROUND(uploads.filesize / 1000000.0, 2) AS size_in_mb,
    uploads.extension,
    uploads.created_at,
    uploads.url
FROM post_uploads
JOIN uploads ON uploads.id = post_uploads.upload_id
JOIN posts ON posts.id = post_uploads.post_id
ORDER BY uploads.filesize DESC
LIMIT 50

다음과 같은 메시지를 받게 됩니다:

PG::UndefinedTable: ERROR:  relation "post_uploads" does not exist
LINE 13: FROM post_uploads
              ^

미래에 이 주제를 찾는 분들을 위해, 이 문제는 https://meta.discourse.org/t/search-attachments-by-storage-name/209945와 관련이 있습니다.

2개의 좋아요

아 네. post_uploads 테이블은 비활성화되었습니다. 이제 uploads와 upload_references 테이블을 사용해야 하는 것 같네요?

리포트 감사합니다. :+1:


필요하시면 업데이트된 버전은 다음과 같습니다 @Ivan_Rapekas:

SELECT posts.id AS post_id,
    uploads.original_filename,
    ROUND(uploads.filesize / 1000000.0, 2) AS size_in_mb,
    uploads.extension,
    uploads.created_at,
    uploads.url
FROM upload_references
JOIN uploads ON uploads.id = upload_references.upload_id
JOIN posts ON posts.id = upload_references.target_id AND upload_references.target_type = 'Post'
ORDER BY uploads.filesize DESC
LIMIT 50
3개의 좋아요

다음으로 수정해야 합니다: :+1:

2개의 좋아요

이 주제는 3일 후 자동으로 닫혔습니다. 더 이상 새로운 답글을 작성할 수 없습니다.