From bfdc0c30478a17db4c40f3805f21764cf4d97f47 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Fri, 3 Jul 2026 14:41:52 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20db:=2004-alter=20close=5Freason=20?= =?UTF-8?q?=EA=B3=84=EC=97=B4=20ALTER=20=EB=B3=B4=EC=A0=95=20+=20=EC=8A=A4?= =?UTF-8?q?=ED=82=A4=EB=A7=88=20=ED=8C=8C=EC=9D=BC=20=EB=82=A0=EC=A7=9C=20?= =?UTF-8?q?rename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 04-alter 에 quotations.close_reason · quotation_settings.mid_action/over_action/regen_limit ALTER 누락분 append. 기존 DB 마이그레이션이 close_reason 개편을 안 담고 있어 UndefinedColumn 나던 것 보정(멱등 IF NOT EXISTS). - postgres-init/01-schema.sql·04-alter.sql → *_20260702.sql 로 rename(스키마 최종 변경일 = 파일명). 사람들이 DB 최신 여부를 파일명으로 판단. - 주석·문서 참조(README·docker-compose·02-learning·agent models·anchoring doc)는 글롭 01-schema*.sql·04-alter*.sql 로 바꿔 다음 rename 때 수정 불필요. Co-Authored-By: Claude Opus 4.8 (1M context) --- README.md | 2 +- agent/common/database/model/models.py | 2 +- docker-compose.yml | 2 +- .../{01-schema.sql => 01-schema_20260702.sql} | 0 postgres-init/02-learning-schema.sql | 2 +- .../{04-alter.sql => 04-alter_20260702.sql} | 14 ++++++++++++-- schedules/anchoring/docs/개발용.md | 2 +- 7 files changed, 17 insertions(+), 7 deletions(-) rename postgres-init/{01-schema.sql => 01-schema_20260702.sql} (100%) rename postgres-init/{04-alter.sql => 04-alter_20260702.sql} (80%) diff --git a/README.md b/README.md index effa92d..d554e1f 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ PostgreSQL (외부, 5432) ```bash # 1) DB 준비 (최초 1회) — 사용할 PostgreSQL 에 스키마 + 시드 적용 -psql -h 127.0.0.1 -p 5432 -U postgres -f postgres-init/01-schema.sql # negosium_db + 도메인 schema +psql -h 127.0.0.1 -p 5432 -U postgres -f postgres-init/01-schema*.sql # negosium_db + 도메인 schema psql -h 127.0.0.1 -p 5432 -U postgres -f postgres-init/02-learning-schema.sql # agent learning 스키마 psql -h 127.0.0.1 -p 5432 -U postgres -f postgres-init/03-seed-negodata.sql # negodata 전용 시드 diff --git a/agent/common/database/model/models.py b/agent/common/database/model/models.py index 7ed8e49..a66e862 100644 --- a/agent/common/database/model/models.py +++ b/agent/common/database/model/models.py @@ -18,7 +18,7 @@ from common.enums import DBType # 모든 ORM 모델의 베이스. insert 시 isinstance 체크에도 사용된다. (backend 와 동일 패턴) # # agent 는 negosium_db 를 backend 와 공유한다. -# - 기존 스키마(company/card/negotiation 등)는 postgres-init/01-schema.sql 이 소유 → 읽기/쓰기만. +# - 기존 스키마(company/card/negotiation 등)는 postgres-init/01-schema*.sql 이 소유 → 읽기/쓰기만. # - RL 학습 자산은 신설 `learning` 스키마(postgres-init/02-learning-schema.sql)에 둔다. MAIN_BASE = declarative_base() diff --git a/docker-compose.yml b/docker-compose.yml index 927f11f..558f0ea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ # agent 서버: http://localhost:9500/docs # # DB 준비(최초 1회): postgres-init 의 SQL 을 대상 DB 에 적용한다. -# psql -h -p -U -f postgres-init/01-schema.sql (단일 negosium_db + 도메인별 schema) +# psql -h -p -U -f postgres-init/01-schema*.sql (단일 negosium_db + 도메인별 schema) # psql -h -p -U -f postgres-init/02-learning-schema.sql (agent learning 스키마) # psql -h -p -U -f postgres-init/03-seed-negodata.sql (negodata 전용 시드: admin / admin1234, company.users) diff --git a/postgres-init/01-schema.sql b/postgres-init/01-schema_20260702.sql similarity index 100% rename from postgres-init/01-schema.sql rename to postgres-init/01-schema_20260702.sql diff --git a/postgres-init/02-learning-schema.sql b/postgres-init/02-learning-schema.sql index 9a1dd5d..43d789f 100644 --- a/postgres-init/02-learning-schema.sql +++ b/postgres-init/02-learning-schema.sql @@ -2,7 +2,7 @@ -- learning : 협상 에이전트(agent) RL 학습 자산 (Q-Table / 경험로그) -- ============================================================ -- negosium_db 안의 7번째 schema. agent 서비스가 소유한다(backend 는 미사용). --- 01-schema.sql 과 동일 컨벤션: FK 미사용(앱 레이어 무결성), TIMESTAMPTZ(UTC), 코드값 SMALLINT(1부터). +-- 01-schema*.sql 과 동일 컨벤션: FK 미사용(앱 레이어 무결성), TIMESTAMPTZ(UTC), 코드값 SMALLINT(1부터). -- -- 멀티테넌트 논리 격리: 모든 테이블에 company_id 컬럼. company.companies.company_id(uuid)를 -- 문자열로 보관하되, 공유 베이스 정책은 예약어 '_base' 를 쓴다(uuid/sentinel 혼용 → VARCHAR). diff --git a/postgres-init/04-alter.sql b/postgres-init/04-alter_20260702.sql similarity index 80% rename from postgres-init/04-alter.sql rename to postgres-init/04-alter_20260702.sql index a2087c5..0c6d53d 100644 --- a/postgres-init/04-alter.sql +++ b/postgres-init/04-alter_20260702.sql @@ -1,6 +1,6 @@ -- 기존 DB ALTER 누적 파일. 새 컬럼/변경은 이 파일에 계속 append 한다. -- 전부 IF NOT EXISTS 라 몇 번을 재실행해도 안전(돌리면 최신 상태로 맞춰짐). --- 신규/리셋 DB 는 01-schema.sql 에 이미 반영돼 있어 이 파일이 필요 없다. +-- 신규/리셋 DB 는 01-schema*.sql 에 이미 반영돼 있어 이 파일이 필요 없다. -- ─────────────────────────────────────────────────────────── -- [2026-06-26] 견적 개편: 가격(매입/판매)·수수료율·앵커링가 + 견적/카드/협력사 분류 컬럼 @@ -54,9 +54,19 @@ CREATE INDEX IF NOT EXISTS idx_notifications_ref_qt_id ON company.notification -- ───────────────────────────────────────────────────────────── -- [2026-07-02] 앵커링 v1.2 — sessions 판정·마킹 컬럼 3종 --- (신규 DB 는 01-schema.sql 에 반영됨. anchoring 스키마 자체(rate_adjustments·뷰)는 +-- (신규 DB 는 01-schema*.sql 에 반영됨. anchoring 스키마 자체(rate_adjustments·뷰)는 -- 모듈 소유 DDL schedules/anchoring/schema.sql 로 적용 — 여기엔 두지 않는다.) ALTER TABLE negotiation.sessions ADD COLUMN IF NOT EXISTS anchor_rate_permille SMALLINT NULL, -- 제안 당시 앵커링 값(천분율) 박제 ADD COLUMN IF NOT EXISTS last_offered_price BIGINT NULL, -- 협력사 마지막 제시가(가격 흔적) ADD COLUMN IF NOT EXISTS anchoring_adjustment_id BIGINT NULL; -- 앵커링 배치 소비 마킹 + +-- ───────────────────────────────────────────────────────────── +-- [2026-07-02] 마감 close_reason 개편 — 견적 마감사유 + 가격정책 3구간 +-- (신규 DB 는 01-schema*.sql 에 반영됨.) +ALTER TABLE quotation.quotations + ADD COLUMN IF NOT EXISTS close_reason SMALLINT NULL; -- 마감 사유(CloseReason 1~8), 미마감이면 NULL +ALTER TABLE quotation.quotation_settings + ADD COLUMN IF NOT EXISTS mid_action SMALLINT NOT NULL DEFAULT 1, -- 가격정책(PriceGateAction): 앵커링가<투찰가≤목표가 처리 + ADD COLUMN IF NOT EXISTS over_action SMALLINT NOT NULL DEFAULT 1, -- 가격정책(PriceGateAction): 목표가<투찰가 처리 + ADD COLUMN IF NOT EXISTS regen_limit SMALLINT NOT NULL DEFAULT 1; -- 재생성 최대 횟수(체인 전체 총합, 사유 무관) diff --git a/schedules/anchoring/docs/개발용.md b/schedules/anchoring/docs/개발용.md index 81d0f47..f6591d0 100644 --- a/schedules/anchoring/docs/개발용.md +++ b/schedules/anchoring/docs/개발용.md @@ -357,7 +357,7 @@ anchoring.current_rates -- 칸별 현재값(최신 조정 행). 여기 없는 주의사항: - `sessions.target_anchoring_price`는 negodata 가 이미 생성 시 채우는 기존 컬럼 — 앵커가 박제로 그대로 활용(신규 컬럼 아님). -- 신규 DB 구축 시 적용 순서: `postgres-init/01~04` → `schedules/anchoring/schema.sql` (IF NOT EXISTS 라 재적용 안전). **sessions 3컬럼은 backend ORM 이 참조하므로 `postgres-init/01-schema.sql`·`04-alter.sql` 에도 반영돼 있다**(backend 가 모듈 DDL 없이도 기동) — anchoring 스키마 자체(테이블·뷰)는 모듈 파일만이 소유. +- 신규 DB 구축 시 적용 순서: `postgres-init/01~04` → `schedules/anchoring/schema.sql` (IF NOT EXISTS 라 재적용 안전). **sessions 3컬럼은 backend ORM 이 참조하므로 `postgres-init/01-schema*.sql`·`04-alter*.sql` 에도 반영돼 있다**(backend 가 모듈 DDL 없이도 기동) — anchoring 스키마 자체(테이블·뷰)는 모듈 파일만이 소유. - backend 모델(`models.py`)에는 **sessions 3컬럼만 추가**한다 — `rate_adjustments` 모델은 backend 에 만들지 않는다(무의존). 배치용 ORM 은 모듈이 자체 보유(읽기전용 sessions/quotations/items 매핑 포함). ---