[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
@@ -4,7 +4,7 @@ from fastapi import Depends
|
||||
|
||||
from common.category_schema import CategorySchemaError, get_schema
|
||||
from common.database.db_session_manager import DB_SESSION_MNG
|
||||
from common.database.model.models import place_links, places, units
|
||||
from common.database.model.models import place_channels, places, place_units
|
||||
from common.enums import DBWRType, ErrorType, JobStatus, JobType, LinkChannel, PlaceCategory, PlaceStatus, SourceType
|
||||
from common.logger import LOG
|
||||
from common.models.gmodel import PageParams, UserInfo
|
||||
@@ -243,6 +243,8 @@ class PlaceService:
|
||||
phone=base.get("phone") or base.get("virtualPhone") or None,
|
||||
latitude=Decimal(str(coord.get("y"))) if coord.get("y") else None,
|
||||
longitude=Decimal(str(coord.get("x"))) if coord.get("x") else None,
|
||||
# 네이버 상세의 분류("펜션"·"카페,디저트"). 주변 맛집 경쟁업소 제외의 폴백 근거(실측 2026-09-08: 있음).
|
||||
category_name=str(base.get("category") or "").strip() or None,
|
||||
)
|
||||
verified = await self.verify_place(user_info, place_id, verify_req)
|
||||
if not verified.result.success:
|
||||
@@ -268,7 +270,7 @@ class PlaceService:
|
||||
title=f"{official} 네이버 플레이스", discovered_by=SourceType.OWNER),
|
||||
)
|
||||
await DB_SESSION_MNG.execute_lambda_claim(
|
||||
place_links.DBType(),
|
||||
place_channels.DBType(),
|
||||
lambda s: self.crud.confirm_link_by_url(
|
||||
s, uuid.UUID(place_id), canonical, uuid.UUID(user_info.user_id), GTime.UTC()
|
||||
),
|
||||
@@ -321,6 +323,9 @@ class PlaceService:
|
||||
"verified_at": now,
|
||||
"verified_by": uuid.UUID(user_info.user_id),
|
||||
}
|
||||
# ★ 값이 왔을 때만 덮는다 — 네이버 URL 재검증이 분류를 못 읽었다고 카카오가 준 값을 지우면 안 된다.
|
||||
if (req.category_name or "").strip():
|
||||
data["external_category"] = req.category_name.strip()[:200]
|
||||
err_type, rowcount = await DB_SESSION_MNG.execute_lambda_claim(
|
||||
places.DBType(),
|
||||
lambda s: self.crud.update_place(s, uid, uuid.UUID(place_id), data),
|
||||
@@ -345,7 +350,7 @@ class PlaceService:
|
||||
discovered_at=now,
|
||||
)
|
||||
await DB_SESSION_MNG.execute_lambda_run(
|
||||
[place_links.DBType()],
|
||||
[place_channels.DBType()],
|
||||
[lambda s: self.crud.add_link(s, link)],
|
||||
)
|
||||
return await self.get_place(user_info, place_id)
|
||||
@@ -358,7 +363,7 @@ class PlaceService:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
list_err, rows = await DB_SESSION_MNG.execute_lambda(
|
||||
units.DBType(),
|
||||
place_units.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.list_units(s, uuid.UUID(place_id)),
|
||||
)
|
||||
@@ -380,7 +385,7 @@ class PlaceService:
|
||||
|
||||
unit = units(place_id=uuid.UUID(place_id), name=req.name.strip(), sort_order=req.sort_order)
|
||||
run_err = await DB_SESSION_MNG.execute_lambda_run(
|
||||
[units.DBType()],
|
||||
[place_units.DBType()],
|
||||
[lambda s: self.crud.add_unit(s, unit)],
|
||||
)
|
||||
if run_err != ErrorType.SUCCESS:
|
||||
@@ -397,7 +402,7 @@ class PlaceService:
|
||||
res.result.SetResult(err_type)
|
||||
return res
|
||||
list_err, rows = await DB_SESSION_MNG.execute_lambda(
|
||||
place_links.DBType(),
|
||||
place_channels.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.list_links(s, uuid.UUID(place_id), confirmed_only),
|
||||
)
|
||||
@@ -430,7 +435,7 @@ class PlaceService:
|
||||
discovered_at=GTime.UTC(),
|
||||
)
|
||||
run_err = await DB_SESSION_MNG.execute_lambda_run(
|
||||
[place_links.DBType()],
|
||||
[place_channels.DBType()],
|
||||
[lambda s: self.crud.add_link(s, link)],
|
||||
)
|
||||
if run_err != ErrorType.SUCCESS:
|
||||
@@ -451,7 +456,7 @@ class PlaceService:
|
||||
return res
|
||||
|
||||
run_err, rowcount = await DB_SESSION_MNG.execute_lambda_claim(
|
||||
place_links.DBType(),
|
||||
place_channels.DBType(),
|
||||
lambda s: self.crud.confirm_link(
|
||||
s, uuid.UUID(place_id), uuid.UUID(link_id), uuid.UUID(user_info.user_id), GTime.UTC()
|
||||
),
|
||||
@@ -492,7 +497,7 @@ class PlaceService:
|
||||
# 채널 URL 발견(Perplexity)은 **잡의 첫 단계**다 — 링크가 하나도 없어도 수집을 시작할 수 있다.
|
||||
# 여기서는 이미 확정된 링크 수만 세어 응답에 실어준다(진행 상황 표시용).
|
||||
link_err, links = await DB_SESSION_MNG.execute_lambda(
|
||||
place_links.DBType(),
|
||||
place_channels.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.list_links(s, uuid.UUID(place_id), True),
|
||||
)
|
||||
@@ -554,7 +559,7 @@ class PlaceService:
|
||||
force 로 재분석할 때 이 엔드포인트를 쓴다."""
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from common.database.model.models import media
|
||||
from common.database.model.models import place_photos
|
||||
from services.external import gemini
|
||||
|
||||
res = Res_StartVision()
|
||||
@@ -817,7 +822,7 @@ class PlaceService:
|
||||
|
||||
★ 근거로 쓸 확인된 fact 가 없으면 잡을 만들지 않는다 —
|
||||
근거 없이 문장을 쓰면 그게 환각이고, 유료 호출만 낭비된다."""
|
||||
from common.database.model.models import facts as facts_model
|
||||
from common.database.model.models import place_facts as facts_model
|
||||
from crud.fact_crud import FactCRUD
|
||||
from services.external import gemini_text
|
||||
|
||||
|
||||
Reference in new issue
Block a user