diff --git a/scripts/sql/cupang_box_rules_seed.sql b/scripts/sql/cupang_box_rules_seed.sql index b08cf04..8f2e25c 100644 --- a/scripts/sql/cupang_box_rules_seed.sql +++ b/scripts/sql/cupang_box_rules_seed.sql @@ -14,20 +14,20 @@ BEGIN; INSERT INTO cupang_box_rules (product_code, product_name_snapshot, box_name, units_per_box, memo, active) VALUES - ('MS-1001', '미라네 1호 세트', '쿠팡박스', 8, '피킹비 750원 · 2호', TRUE), - ('MS-1002', '미라네 2호 세트', '쿠팡박스', 8, '피킹비 1100원 · 2호', TRUE), - ('MS-1003', '미라네 3호 세트', '쿠팡박스', 8, '피킹비 1200원 · 2호', TRUE), - ('MS-1004', '미라네 4호 세트', '쿠팡박스', 8, '피킹비 1000원 · 2호', TRUE), - ('MS-1005', '미라네 5호 세트', '쿠팡박스', 8, '피킹비 650원 · 2호', TRUE), - ('MS-1006', '미라네 6호 세트', '쿠팡박스', 8, '피킹비 750원 · 2호', TRUE), - ('MS-1007', '미라네 7호 세트', '쿠팡박스', 8, '피킹비 850원 · 2호', TRUE), - ('MS-9812', '황토 김치통 1호세트', '쿠팡박스', 8, '피킹비 750원 · 2호', TRUE), - ('MS-9813', '황토 김치통 2호세트', '쿠팡박스', 8, '피킹비 650원 · 2호', TRUE), - ('MS-9814', '황토 김치통 3호세트', '쿠팡박스', 8, '피킹비 750원 · 2호', TRUE), - ('MS-9815', '황토 김치통 4호세트', '쿠팡박스', 2, '피킹비 850원 · 3호', TRUE), - ('MS-9816', '황토 김치통 5호세트', '쿠팡박스', 2, '피킹비 900원 · 3호', TRUE), - ('MS-9817', '황토 김치통 6호세트', '쿠팡박스', 1, '피킹비 1000원 · 6호', TRUE), - ('MS-9818', '황토 김치통 7호세트', '쿠팡박스', 1, '피킹비 1100원 · 6호', TRUE) + ('MS-1001', '미라네 1호 세트', '쿠팡박스', 8, '피킹비 750원', TRUE), + ('MS-1002', '미라네 2호 세트', '쿠팡박스', 8, '피킹비 1100원', TRUE), + ('MS-1003', '미라네 3호 세트', '쿠팡박스', 8, '피킹비 1200원', TRUE), + ('MS-1004', '미라네 4호 세트', '쿠팡박스', 8, '피킹비 1000원', TRUE), + ('MS-1005', '미라네 5호 세트', '쿠팡박스', 8, '피킹비 650원', TRUE), + ('MS-1006', '미라네 6호 세트', '쿠팡박스', 8, '피킹비 750원', TRUE), + ('MS-1007', '미라네 7호 세트', '쿠팡박스', 8, '피킹비 850원', TRUE), + ('MS-9812', '황토 김치통 1호세트', '쿠팡박스', 8, '피킹비 750원', TRUE), + ('MS-9813', '황토 김치통 2호세트', '쿠팡박스', 8, '피킹비 650원', TRUE), + ('MS-9814', '황토 김치통 3호세트', '쿠팡박스', 8, '피킹비 750원', TRUE), + ('MS-9815', '황토 김치통 4호세트', '쿠팡박스', 2, '피킹비 850원', TRUE), + ('MS-9816', '황토 김치통 5호세트', '쿠팡박스', 2, '피킹비 900원', TRUE), + ('MS-9817', '황토 김치통 6호세트', '쿠팡박스', 1, '피킹비 1000원', TRUE), + ('MS-9818', '황토 김치통 7호세트', '쿠팡박스', 1, '피킹비 1100원', TRUE) ON CONFLICT (product_code) DO UPDATE SET product_name_snapshot = EXCLUDED.product_name_snapshot, box_name = EXCLUDED.box_name, diff --git a/scripts/sql/cupang_box_rules_seed2.sql b/scripts/sql/cupang_box_rules_seed2.sql index 02c0352..7a7526f 100644 --- a/scripts/sql/cupang_box_rules_seed2.sql +++ b/scripts/sql/cupang_box_rules_seed2.sql @@ -15,7 +15,7 @@ -- ════════════════════════════════════════════════════════════ BEGIN; --- box_no: 원자료의 박스 호수. 박스명은 '쿠팡박스' 로 통일하고 호수는 memo 에 남긴다. +-- box_no: 원자료의 박스 호수. 참고용 컬럼이며 memo 에는 넣지 않는다(피킹비만 기록). CREATE TEMP TABLE _seed2 ( product_name TEXT, picking_fee INTEGER, @@ -50,7 +50,7 @@ SELECT p.product_code, p.product_name, '쿠팡박스', s.units_per_box, - '피킹비 ' || s.picking_fee || '원 · ' || s.box_no, + '피킹비 ' || s.picking_fee || '원', TRUE FROM _seed2 s JOIN cupang_products p diff --git a/scripts/sql/cupang_box_rules_strip_memo_suffix.sql b/scripts/sql/cupang_box_rules_strip_memo_suffix.sql new file mode 100644 index 0000000..0f8b624 --- /dev/null +++ b/scripts/sql/cupang_box_rules_strip_memo_suffix.sql @@ -0,0 +1,47 @@ +-- ════════════════════════════════════════════════════════════ +-- 쿠팡 밀크런 — 박스 입수량 규칙 memo 에서 피킹비 뒤 꼬리말 제거 (cupang_db) +-- +-- 배경: cupang_box_rules_unify_box_name.sql 이 박스명을 '쿠팡박스' 로 통일하면서 +-- 기존 호수(2호/3호/6호)를 memo 뒤에 ' · 2호' 형태로 옮겨 적었다. +-- 이제 화면에서 불필요하므로 '피킹비 750원' 만 남기고 뒤를 지운다. +-- +-- 변경 전: 피킹비 750원 · 2호 +-- 변경 후: 피킹비 750원 +-- +-- 실행 전 반드시 백업: +-- docker exec postgres-db pg_dump -U postgres -d cupang_db -t cupang_box_rules \ +-- > ~/backup/cupang_box_rules_$(date +%F_%H%M).sql +-- +-- 실행: +-- docker exec -i postgres-db psql -U postgres -d cupang_db \ +-- < /opt/www/main/scripts/sql/cupang_box_rules_strip_memo_suffix.sql +-- ════════════════════════════════════════════════════════════ + +-- ── 1) 변경 대상 미리보기 (커밋 전에 눈으로 확인) ── +SELECT product_code AS "제품코드", + memo AS "변경전_메모", + btrim(regexp_replace(memo, '\s*·.*$', '')) AS "변경후_메모" +FROM cupang_box_rules +WHERE memo LIKE '%·%' +ORDER BY product_code; + +BEGIN; + +-- ── 2) '·' 이후를 잘라낸다 (피킹비 금액까지만 남김) ── +UPDATE cupang_box_rules +SET memo = btrim(regexp_replace(memo, '\s*·.*$', '')) +WHERE memo LIKE '%·%'; + +COMMIT; + +-- ── 3) 결과 확인: '·' 남은 행이 0 이어야 정상 ── +SELECT count(*) AS "꼬리말_남은_건수" +FROM cupang_box_rules +WHERE memo LIKE '%·%'; + +SELECT product_code AS "제품코드", + product_name_snapshot AS "제품명", + units_per_box AS "입수량", + memo AS "메모" +FROM cupang_box_rules +ORDER BY product_code;