[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 facts, places, units
|
||||
from common.database.model.models import place_facts, places, place_units
|
||||
from common.enums import (
|
||||
FACT_STATUS_TRANSITIONS,
|
||||
PUBLISHABLE_FACT_STATUSES,
|
||||
@@ -121,7 +121,7 @@ class FactService:
|
||||
return res
|
||||
|
||||
list_err, rows = await DB_SESSION_MNG.execute_lambda(
|
||||
facts.DBType(),
|
||||
place_facts.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.list_facts(s, uuid.UUID(place_id), unit_id, None, publishable_only, True),
|
||||
)
|
||||
@@ -195,7 +195,7 @@ class FactService:
|
||||
unit_id = unit_map.get(fact.unit_name) if fact.unit_name else None
|
||||
if fact.unit_name and unit_id is None:
|
||||
row.reason = f"'{fact.unit_name}' 단위가 아직 없다 — 수집으로 객실·메뉴가 먼저 만들어져야 한다"
|
||||
res.facts.append(row)
|
||||
res.place_facts.append(row)
|
||||
res.rejected += 1
|
||||
continue
|
||||
|
||||
@@ -212,7 +212,7 @@ class FactService:
|
||||
else:
|
||||
row.reason = write.result.desc or "저장 실패"
|
||||
res.rejected += 1
|
||||
res.facts.append(row)
|
||||
res.place_facts.append(row)
|
||||
|
||||
LOG.i(f"[fact] 붙여넣기 추출 — 저장 {res.stored}건 · 반려 {res.rejected}건 (place={place_id})")
|
||||
return res
|
||||
@@ -220,7 +220,7 @@ class FactService:
|
||||
async def _unit_map(self, place_id: str) -> dict:
|
||||
"""단위 이름 → unit_id. 붙여넣기 값이 어느 객실 것인지 잇는 데만 쓴다."""
|
||||
err, rows = await DB_SESSION_MNG.execute_lambda(
|
||||
units.DBType(),
|
||||
place_units.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.place_crud.list_units(s, uuid.UUID(place_id)),
|
||||
)
|
||||
@@ -264,7 +264,7 @@ class FactService:
|
||||
|
||||
pid = uuid.UUID(place_id)
|
||||
pub_err, published = await DB_SESSION_MNG.execute_lambda(
|
||||
facts.DBType(),
|
||||
place_facts.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.get_published_fact(s, pid, req.unit_id, req.key),
|
||||
)
|
||||
@@ -278,7 +278,7 @@ class FactService:
|
||||
# ── 값이 그대로다 — 검증을 초기화하지 않고 '언제 다시 확인했는지'만 갱신 ──
|
||||
if same_value:
|
||||
run_err, _rc = await DB_SESSION_MNG.execute_lambda_claim(
|
||||
facts.DBType(),
|
||||
place_facts.DBType(),
|
||||
lambda s: self.crud.refresh_collected(s, published.fact_id, req.source_type.value, req.source_url, now),
|
||||
)
|
||||
if run_err != ErrorType.SUCCESS:
|
||||
@@ -299,7 +299,7 @@ class FactService:
|
||||
target_status = FactStatus.PENDING_OWNER if published is not None else FactStatus.UNVERIFIED
|
||||
|
||||
cand_err, candidate = await DB_SESSION_MNG.execute_lambda(
|
||||
facts.DBType(),
|
||||
place_facts.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.get_candidate(s, pid, req.unit_id, req.key, req.source_type.value),
|
||||
)
|
||||
@@ -310,7 +310,7 @@ class FactService:
|
||||
# 같은 출처가 이미 올려둔 후보가 있으면 갱신한다(같은 후보가 계속 쌓이지 않게).
|
||||
if candidate is not None:
|
||||
run_err, _rc = await DB_SESSION_MNG.execute_lambda_claim(
|
||||
facts.DBType(),
|
||||
place_facts.DBType(),
|
||||
lambda s: self.crud.update_candidate(
|
||||
s, candidate.fact_id, req.value, req.source_url, target_status.value, now
|
||||
),
|
||||
@@ -334,7 +334,7 @@ class FactService:
|
||||
expires_at=req.expires_at,
|
||||
)
|
||||
run_err = await DB_SESSION_MNG.execute_lambda_run(
|
||||
[facts.DBType()],
|
||||
[place_facts.DBType()],
|
||||
[lambda s: self.crud.add_fact(s, fact)],
|
||||
)
|
||||
if run_err != ErrorType.SUCCESS:
|
||||
@@ -364,7 +364,7 @@ class FactService:
|
||||
expires_at=req.expires_at,
|
||||
)
|
||||
run_err = await DB_SESSION_MNG.execute_lambda_run(
|
||||
[facts.DBType()],
|
||||
[place_facts.DBType()],
|
||||
[
|
||||
lambda s: self._expire_then_ok(s, pid, req, now),
|
||||
lambda s: self.crud.add_fact(s, fact),
|
||||
@@ -387,7 +387,7 @@ class FactService:
|
||||
|
||||
async def _reload(self, res, pid, fact_id):
|
||||
_e, row = await DB_SESSION_MNG.execute_lambda(
|
||||
facts.DBType(),
|
||||
place_facts.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.get_fact(s, pid, fact_id),
|
||||
)
|
||||
@@ -409,7 +409,7 @@ class FactService:
|
||||
pid = uuid.UUID(place_id)
|
||||
fid = uuid.UUID(fact_id)
|
||||
get_err, fact = await DB_SESSION_MNG.execute_lambda(
|
||||
facts.DBType(),
|
||||
place_facts.DBType(),
|
||||
DBWRType.DB_READ.value,
|
||||
lambda s: self.crud.get_fact(s, pid, fid),
|
||||
)
|
||||
@@ -445,7 +445,7 @@ class FactService:
|
||||
if promoting:
|
||||
funcs.append(lambda s: self._reject_others_ok(s, pid, fact, now, fid))
|
||||
|
||||
run_err = await DB_SESSION_MNG.execute_lambda_run([facts.DBType()], funcs)
|
||||
run_err = await DB_SESSION_MNG.execute_lambda_run([place_facts.DBType()], funcs)
|
||||
if run_err != ErrorType.SUCCESS:
|
||||
res.result.SetResult(
|
||||
ErrorType.FACT_INVALID_TRANSITION if run_err == ErrorType.DB_EMPTY_DATA else run_err
|
||||
|
||||
Reference in new issue
Block a user