[refactor] postgres-init,solution: DB 구조 재편 — 스키마 해체 · 공용 콘텐츠 한 벌 · 마이그레이션 체계
도메인별 스키마(company·place·fact·local·site·job)를 걷어내고 public 한 벌로 폈다.
스키마 한정자가 붙은 순간부터 ORM·raw SQL·테스트 픽스처가 각자 그 이름을 들고 다녀야 했다.
- 공용 콘텐츠를 한 테이블로 되돌린다. spots·region_stories 를 따로 파 놓고 보니
같은 성격이 세 곳으로 갈라져 있었다 — `area_contents` 가 처음부터 content_type 으로
종류를 가르는 설계였고 그걸 쓰면 됐다. 관계(거리·숨김)만 `place_area_refs` 로 남긴다.
- migrations/ + scripts/migrate.py: `init.sql` 은 **DB 를 처음 만들 때만** 돈다. 파일에
컬럼을 더해도 이미 데이터가 든 DB 에는 반영되지 않는다 — 실제로 TourAPI 가 주변 정보를
받아 와도 저장할 곳이 없어 축제·맛집이 0건이었고, 화면에는 "그냥 안 나오는 것" 으로만 보였다.
DECISIONS.md 가 예고한 그대로다("운영 DB 가 생기는 순간 다시 필요해진다").
Alembic 을 쓰지 않는 이유는 스키마 정의가 이미 두 곳(ORM·init.sql)이라 세 번째를
더하면 어긋날 자리가 하나 더 생기기 때문이다.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7bbeb068a8
commit
64ce467f21
189 files changed
+13374
-5023
No files matched your search
@@ -10,7 +10,7 @@ import uuid
|
||||
|
||||
from common.category_schema import CategorySchemaError, get_schema
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.database.model.models import facts, faqs, place_links, places, units
|
||||
from common.database.model.models import place_facts, place_faqs, place_channels, places, place_units
|
||||
from common.enums import (
|
||||
PUBLISHABLE_FACT_STATUSES,
|
||||
DBWRType,
|
||||
@@ -64,7 +64,7 @@ async def run_copy(job: dict) -> dict:
|
||||
# ★ 노출 가능한 fact 만 근거로 준다. 미검증 값으로 쓴 문장은 그 자체가 미검증이다.
|
||||
pid = uuid.UUID(place_id)
|
||||
f_err, fact_rows = await DB_SESSION_MNG.execute_lambda(
|
||||
facts.DBType(),
|
||||
place_facts.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: _fact_crud.list_facts(s, pid, None, None, True, True),
|
||||
)
|
||||
@@ -81,7 +81,7 @@ async def run_copy(job: dict) -> dict:
|
||||
for r in fact_rows
|
||||
if r.unit_id is None and (r.value or "").strip()
|
||||
]
|
||||
# ★ 수집 원문도 근거로 넘긴다 — fact 가 아니라 place_links.raw 에 박제된 글이다.
|
||||
# ★ 수집 원문도 근거로 넘긴다 — fact 가 아니라 place_channels.raw 에 박제된 글이다.
|
||||
#
|
||||
# 왜 필요한가: 소개 원문(TourAPI overview·네이버 description)에만 있는 정보가 있다.
|
||||
# '전면 통창 실내 온수풀', '판교역에서 3분' 같은 것들인데, 이게 근거에 없으면
|
||||
@@ -91,7 +91,7 @@ async def run_copy(job: dict) -> dict:
|
||||
# 원문을 그 칸에 넣었더니 457자 원문이 발행본의 '숙소 소개' 를 차지했다(2026-08-31).
|
||||
# 근거로만 쓰고 저장은 하지 않는다 — 원문은 화면에 나가지 않는다.
|
||||
l_err, link_rows = await DB_SESSION_MNG.execute_lambda(
|
||||
place_links.DBType(),
|
||||
place_channels.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: _place_crud.list_links(s, pid, True),
|
||||
)
|
||||
@@ -110,7 +110,7 @@ async def run_copy(job: dict) -> dict:
|
||||
# 요금표만 올라온 모텔은 사업장 fact 가 0건이고 객실 fact 만 있다 — 쓸 근거가 있는데도
|
||||
# "근거 없음"으로 끝나 소개문·FAQ 가 영구히 생기지 않았다.
|
||||
u_err, unit_rows = await DB_SESSION_MNG.execute_lambda(
|
||||
units.DBType(),
|
||||
place_units.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: _place_crud.list_units(s, pid),
|
||||
)
|
||||
@@ -196,15 +196,15 @@ async def run_copy(job: dict) -> dict:
|
||||
|
||||
# 확인 안 된 기존 생성 FAQ 는 내리고 새로 넣는다. 사람이 확인한 FAQ 는 건드리지 않는다.
|
||||
await DB_SESSION_MNG.execute_lambda_claim(
|
||||
faqs.DBType(),
|
||||
place_faqs.DBType(),
|
||||
lambda s: _faq_crud.expire_generated(s, pid, now),
|
||||
)
|
||||
for order, faq in enumerate(copy.faqs or []):
|
||||
for order, faq in enumerate(copy.place_faqs or []):
|
||||
if not faq.fact_keys:
|
||||
# ★ 근거 없는 FAQ 는 저장하지 않는다.
|
||||
stat["rejected"].append([faq.question, "근거 fact 없음"])
|
||||
continue
|
||||
row = faqs(
|
||||
row = place_faqs(
|
||||
place_id=pid,
|
||||
question=faq.question,
|
||||
answer=faq.answer,
|
||||
@@ -214,7 +214,7 @@ async def run_copy(job: dict) -> dict:
|
||||
sort_order=order,
|
||||
)
|
||||
run_err = await DB_SESSION_MNG.execute_lambda_run(
|
||||
[faqs.DBType()],
|
||||
[place_faqs.DBType()],
|
||||
[lambda s, r=row: _faq_crud.add_faq(s, r)],
|
||||
)
|
||||
if run_err == ErrorType.SUCCESS:
|
||||
|
||||
Reference in new issue
Block a user