Files
wace_rps/docs/migration/sales/ddl-extracted
hjjeong 4175ae77c1 영업관리 wace 컬럼 정합성 강화 + project_mgmt 도입
- project_mgmt 테이블 신규(75컬럼/89건) — wace 운영 동일 schema 추출. 판매·매출관리 메인 테이블
- 판매·매출 SQL을 contract_item 기반 → project_mgmt 메인 + sales_registration LEFT JOIN으로 전면 재작성
  * 요청납기 COALESCE(CI.due_date, T.due_date, CM.due_date) 패턴
  * 환종/serial_no는 sales_registration 우선, contract_item_serial 집계 fallback
  * 판매상태 wace 로직 한글 라벨(미판매/완판/분할판매) 동적 계산
  * 매출관리는 shippingDateRequired EXISTS 필터로 출하 등록된 프로젝트만 표시
- 주문서: order_date 매핑 CONTRACT_DATE → ORDER_DATE 정정, 원화총액·고객사요청사항 SQL 추가
- 견적/주문/판매 page.tsx에서 wace 블록 주석 컬럼 제거(제품구분/국내·해외/접수일/반납사유 등 14개)
- 환종 raw 코드 → contract_currency_name 한글명 바인딩으로 정정

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 16:50:45 +09:00
..

추출된 DDL (wace_plm 운영 DB)

추출일: 2026-05-07 출처: 211.115.91.141:11133/waceplm (PostgreSQL 16.8) 추출 방법: information_schema 쿼리 (pg_dump 14↔16 버전 불일치로 직접 추출 불가)

db/dbexport.pgsql(2026-03-26 시점)에 누락된 테이블을 운영 DB에서 직접 추출해 재구성.

파일 목록

파일 테이블 비고
100_create_estimate_template.sql estimate_template, estimate_template_item 견적관리(estimateList_new) 메인. 운영 5건
101_create_sales_registration.sql sales_registration, shipment_log 판매·매출관리 메인. 운영 10건 / 0건
102_create_mail_log.sql mail_log 메일 이력. 운영 7,805건. PK 없음
103_create_contract_mgmt.sql contract_mgmt, contract_item, contract_item_serial, contract_mgmt_option 영업/계약 헤더+라인+시리얼+옵션 (견적/주문/판매/매출 공통 헤더)

운영 데이터 카운트 (참고)

estimate_template       : 5
estimate_template_item  : 7
sales_registration      : 10
shipment_log            : 0
mail_log                : 7,805

→ 견적/판매 도메인은 사실상 신규 시스템. 데이터 이주 부담 거의 없음.

핵심 발견

1. 매출관리(revenue)는 별도 테이블이 아님

기존 04-revenue.md에서는 final_data, end_count, tax_invoice_*, transaction_statement_* 같은 별도 테이블을 가정했으나, 실제로는 모두 shipment_log 컬럼으로 존재:

매출관리 항목 위치
매출마감일 shipment_log.sales_deadline_date (varchar 10)
과세구분 shipment_log.tax_type
세금계산서 발행일 shipment_log.tax_invoice_date
수출신고필증 번호 shipment_log.export_decl_no
선적일자 shipment_log.loading_date
매출전표일 shipment_log.sales_slip_date
매출전표 menu_sq shipment_log.sales_slip_menu_sq

→ 마감/세금계산서/수출신고는 shipment_log 행 INSERT/UPDATE로 처리.

2. sales_registration ↔ shipment_log 관계

  • sales_registration (PK sale_no BIGSERIAL, UNIQUE project_no) — 프로젝트당 1건 헤더
  • shipment_log (PK log_id BIGSERIAL, FK parent_sale_no → sales_registration.sale_no) — 분할출하·매출 이력 라인
  • is_split_record 기본값 true — 즉 shipment_log는 기본이 분할 레코드 가정
  • target_objidcontract_mgmt.objid (FK처럼 사용)

3. estimate_template은 contract_objid로 묶임

  • 1 contract → N templates (template_type='1'=일반, '2'=장비, 추가가능)
  • categories_json 컬럼에 그룹/소그룹 구조 저장 (JSON)
  • manager_name, manager_contact, note_remarks, show_total_row 등은 database/add_manager_info_to_estimate_template.sql에 별도 ALTER로 추가됐던 컬럼들 — DDL에 통합됨

4. mail_log는 PK 없음

운영에서 PK 없이 사용 중. vexplor_rps에는 마이그레이션 시 id BIGSERIAL PRIMARY KEY 추가 권장.

사용

# vexplor_rps DB에 적용 (테스트 환경 먼저 권장)
psql -h <vexplor_rps_host> -U <user> -d <db> -f 100_create_estimate_template.sql
psql -h <vexplor_rps_host> -U <user> -d <db> -f 101_create_sales_registration.sql
psql -h <vexplor_rps_host> -U <user> -d <db> -f 102_create_mail_log.sql

db/migrations/ 정식 위치로 옮길 때는 vexplor_rps 마이그레이션 번호 체계에 맞춰 파일명 변경.

추출 명령 재현

서버가 PG 16, 로컬 pg_dump가 PG 14인 경우 pg_dump가 실패하므로 information_schema 쿼리로 추출:

PGPASSWORD='<pwd>' psql -h 211.115.91.141 -p 11133 -U postgres -d waceplm -t -A -F '|' -c "
SELECT table_name||'|'||column_name||'|'||data_type||'|'||COALESCE(character_maximum_length::text,'')||'|'||is_nullable||'|'||COALESCE(column_default,'')
FROM information_schema.columns
WHERE table_schema='public' AND table_name IN ('estimate_template','estimate_template_item','sales_registration','shipment_log','mail_log')
ORDER BY table_name, ordinal_position;"

PK/UNIQUE는 information_schema.table_constraints + key_column_usage, 인덱스는 pg_indexes, 시퀀스는 information_schema.sequences, 컬럼 코멘트는 pg_description JOIN.