260330:1011 Addied correspondence_revieion_attcahments table table #01
CI / CD Pipeline / build (push) Failing after 21m19s
CI / CD Pipeline / deploy (push) Has been skipped

This commit is contained in:
admin
2026-03-30 10:11:40 +07:00
parent 1c6fec6c65
commit c83588ab43
287 changed files with 15117 additions and 69 deletions
@@ -1,4 +1,4 @@
-- ==========================================================
-- ==========================================================
-- DMS v1.8.0 Schema Part 3/3: Views, Indexes, Partitioning
-- รัน: หลังจาก 02-schema-tables.sql เสร็จ
-- ==========================================================
@@ -397,16 +397,20 @@ SELECT 'CORRESPONDENCE' AS document_type,
p.uuid AS project_uuid,
p.project_code,
p.project_name,
COUNT(ca.attachment_id) AS attachment_count,
COUNT(cra.attachment_id) AS attachment_count,
MAX(a.created_at) AS latest_attachment_date
FROM correspondences c
INNER JOIN projects p ON c.project_id = p.id
LEFT JOIN correspondence_attachments ca ON c.id = ca.correspondence_id
LEFT JOIN attachments a ON ca.attachment_id = a.id
INNER JOIN projects p ON c.project_id = p.id -- [FIX] JOIN ผ่าน correspondence_revisions เพราะไฟล์ผูกกับ revision ไม่ใช่ correspondence master
LEFT JOIN correspondence_revisions cr ON c.id = cr.correspondence_id
AND cr.is_current = TRUE
LEFT JOIN correspondence_revision_attachments cra ON cr.id = cra.correspondence_revision_id
LEFT JOIN attachments a ON cra.attachment_id = a.id
WHERE c.deleted_at IS NULL
GROUP BY c.id,
c.uuid,
c.correspondence_number,
c.project_id,
p.uuid,
p.project_code,
p.project_name
UNION ALL