diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-05-15 01:22:37 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-05-15 01:22:37 +0000 |
| commit | cab86af033bb2295f9e6d8c6d0df52ab76621c3d (patch) | |
| tree | 68653316b0204e8c8f0640e58a01720554c19dec /db/migrations/0070_tiny_maximus.sql | |
| parent | 9eb8e80f4f736c4edffa650c685d1f170ca51aa1 (diff) | |
(대표님) procurement rfq 관련 DB 스키마 추가
Diffstat (limited to 'db/migrations/0070_tiny_maximus.sql')
| -rw-r--r-- | db/migrations/0070_tiny_maximus.sql | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/db/migrations/0070_tiny_maximus.sql b/db/migrations/0070_tiny_maximus.sql new file mode 100644 index 00000000..fdd7290e --- /dev/null +++ b/db/migrations/0070_tiny_maximus.sql @@ -0,0 +1,70 @@ +DROP VIEW "public"."vendor_documents_view";--> statement-breakpoint +CREATE VIEW "public"."vendor_documents_view" AS ( + SELECT + d.id, + d.doc_number, + d.title, + d.pic, + d.status, + d.issued_date, + + d.contract_id, + + ( + SELECT id FROM issue_stages + WHERE document_id = d.id + ORDER BY created_at DESC LIMIT 1 + ) AS latest_stage_id, + ( + SELECT stage_name FROM issue_stages + WHERE document_id = d.id + ORDER BY created_at DESC LIMIT 1 + ) AS latest_stage_name, + ( + SELECT plan_date FROM issue_stages + WHERE document_id = d.id + ORDER BY created_at DESC LIMIT 1 + ) AS latest_stage_plan_date, + ( + SELECT actual_date FROM issue_stages + WHERE document_id = d.id + ORDER BY created_at DESC LIMIT 1 + ) AS latest_stage_actual_date, + + ( + SELECT r.id FROM revisions r + JOIN issue_stages i ON r.issue_stage_id = i.id + WHERE i.document_id = d.id + ORDER BY r.created_at DESC LIMIT 1 + ) AS latest_revision_id, + ( + SELECT r.revision FROM revisions r + JOIN issue_stages i ON r.issue_stage_id = i.id + WHERE i.document_id = d.id + ORDER BY r.created_at DESC LIMIT 1 + ) AS latest_revision, + ( + SELECT r.uploader_type FROM revisions r + JOIN issue_stages i ON r.issue_stage_id = i.id + WHERE i.document_id = d.id + ORDER BY r.created_at DESC LIMIT 1 + ) AS latest_revision_uploader_type, + ( + SELECT r.uploader_name FROM revisions r + JOIN issue_stages i ON r.issue_stage_id = i.id + WHERE i.document_id = d.id + ORDER BY r.created_at DESC LIMIT 1 + ) AS latest_revision_uploader_name, + + ( + SELECT COUNT(*) FROM document_attachments a + JOIN revisions r ON a.revision_id = r.id + JOIN issue_stages i ON r.issue_stage_id = i.id + WHERE i.document_id = d.id + ) AS attachment_count, + + d.created_at, + d.updated_at + FROM documents d + JOIN contracts c ON d.contract_id = c.id + );
\ No newline at end of file |
