Files
jongryangje/docs/기본 개발계획/테이블/00-테이블_목록_및_ERD.md
2026-04-08 00:23:55 +09:00

136 lines
4.8 KiB
Markdown

# DB 테이블 목록 및 ERD
> 노션 ERD·웹 기능목록·`06-데이터베이스정리구조.md` 네이밍 규칙을 반영한 테이블 설계.
> 지자체(`lg_idx`) 기준 멀티테넌트, 데이터 격리.
---
## 1. 테이블 목록 및 역할
| 테이블 | PK | 지자체 FK | 설명 |
|--------|-----|-----------|------|
| **local_government** | lg_idx | — | 지자체 마스터(테넌트 루트) |
| **member** | mb_idx | mb_lg_idx (nullable) | 회원(로그인·권한). 지자체관리자만 lg 연결 |
| **member_log** | mll_idx | — | 로그인/로그아웃 이력 |
| **designated_shop** | ds_idx | ds_lg_idx | 지정 판매소. 고정 가상계좌(va) 보유 |
| **code_kind** | ck_idx | — | 기본코드 종류(도/시/구, 봉투 구분 등) |
| **code_detail** | cd_idx | — | 종류별 세부 코드. ck_idx FK |
| **product** | pr_idx | pr_lg_idx | 지자체별 취급 품목(규격·용량) |
| **product_price** | pp_idx | pp_lg_idx | 적용일자별 단가(발주/도매/소비자가) |
| **packaging_unit** | pu_idx | pu_lg_idx | 박스당 팩·팩당 낱장 등 포장 단위 |
| **agent** | ag_idx | ag_lg_idx | 판매 대행소(은행 등) |
| **contact** | ct_idx | ct_lg_idx | 담당자(구/군/대행소/제작업체) |
| **company** | co_idx | co_lg_idx | 업체(협회·제작업체·회수업체) |
| **beneficiary** | bf_idx | bf_lg_idx | 무료용 대상자 |
| **purchase_order** | po_idx | po_lg_idx | 발주(지자체 → 제작업체) |
| **inbound_receipt** | ir_idx | ir_lg_idx | 입고 내역(LOT·바코드 연동) |
| **sales_order** | so_idx | so_lg_idx | 판매소 주문. 데이터 격리용 lg_idx |
| **stock_transaction** | st_idx | st_lg_idx | 수불(입고/판매/불출/파기) |
---
## 2. 엔티티 관계 다이어그램 (ERD)
```mermaid
erDiagram
local_government ||--o{ member : "mb_lg_idx (지자체관리자)"
local_government ||--o{ designated_shop : "ds_lg_idx"
designated_shop ||--o| member : "ds_mb_idx (로그인 1:1)"
local_government ||--o{ product : "pr_lg_idx"
local_government ||--o{ product_price : "pp_lg_idx"
local_government ||--o{ packaging_unit : "pu_lg_idx"
local_government ||--o{ agent : "ag_lg_idx"
local_government ||--o{ contact : "ct_lg_idx"
local_government ||--o{ company : "co_lg_idx"
local_government ||--o{ beneficiary : "bf_lg_idx"
local_government ||--o{ purchase_order : "po_lg_idx"
local_government ||--o{ inbound_receipt : "ir_lg_idx"
local_government ||--o{ sales_order : "so_lg_idx"
local_government ||--o{ stock_transaction : "st_lg_idx"
designated_shop ||--o{ sales_order : "so_ds_idx"
product ||--o{ product_price : "pp_pr_idx"
product ||--o{ inbound_receipt : "ir_pr_idx"
product ||--o{ stock_transaction : "st_pr_idx"
purchase_order ||--o{ inbound_receipt : "ir_po_idx (LOT)"
sales_order ||--o{ stock_transaction : "참조"
local_government {
int lg_idx PK
string lg_name
string lg_code
string lg_sido
string lg_gugun
tinyint lg_state
datetime lg_regdate
}
member {
int mb_idx PK
int mb_lg_idx FK "nullable"
string mb_id
string mb_passwd
string mb_name
tinyint mb_level "1=일반,2=지정판매소,3=지자체,4=super"
tinyint mb_state
datetime mb_regdate
}
designated_shop {
int ds_idx PK
int ds_lg_idx FK
int ds_mb_idx FK "nullable"
string ds_shop_no
string ds_name
string ds_va_number "고정 가상계좌"
string ds_status "정상,폐업,직권해지"
datetime ds_regdate
}
product {
int pr_idx PK
int pr_lg_idx FK
string pr_type "일반,음식물,재사용"
string pr_capacity "3L,5L,10L"
datetime pr_regdate
}
sales_order {
int so_idx PK
int so_lg_idx FK "데이터 격리"
int so_ds_idx FK
datetime so_order_date
int so_total_amount
string so_payment_status "입금대기,완료,취소"
}
inbound_receipt {
int ir_idx PK
int ir_lg_idx FK
int ir_pr_idx FK
int ir_po_idx FK "LOT"
string ir_lot_number
int ir_quantity
datetime ir_receipt_date
}
stock_transaction {
int st_idx PK
int st_lg_idx FK
int st_pr_idx FK
string st_trans_type "IN,OUT,FREE,DISCARD"
int st_quantity
int st_reference_id "so_idx or ir_idx 등"
datetime st_trans_date
}
```
---
## 3. 참조 자료
- **ERD·요구사항**: `docs/종량제 관련 자료/종량제 개발목록/노션_정리_03-WBS_데이터베이스_ERD.md`
- **ERD 이미지**: `docs/종량제 관련 자료/ss_gbms/ss_gbms/1-5.png`
- **네이밍 규칙**: `docs/개발 규칙/06-데이터베이스정리구조.md`