[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
@@ -9,9 +9,13 @@ import {customFetch} from '@/api/mutator/custom-fetch';
|
||||
import {toast} from 'sonner';
|
||||
|
||||
type Status = 1 | 2 | 3;
|
||||
// LocalContentType — common/enums.py 와 값을 맞춘다. WEATHER(1) 은 사업장 발행본에 실시간으로
|
||||
// 붙는 별도 흐름이라 이 화면에서는 다루지 않는다(services/local_content_service.get_weather).
|
||||
type ContentType = 2 | 3 | 4;
|
||||
|
||||
type LocalContent = {
|
||||
id: string;
|
||||
contentType: ContentType;
|
||||
title: string;
|
||||
region: string;
|
||||
period: string;
|
||||
@@ -24,10 +28,15 @@ type LocalContent = {
|
||||
};
|
||||
|
||||
const STATUS_LABEL: Record<Status, string> = {1: '검수 대기', 2: '발행됨', 3: '종료됨'};
|
||||
const TYPE_LABEL: Record<ContentType, string> = {2: '축제', 3: '관광지', 4: '맛집'};
|
||||
const TYPE_BADGE_VARIANT: Record<ContentType, 'accent' | 'default' | 'outline'> = {
|
||||
2: 'accent', 3: 'default', 4: 'outline',
|
||||
};
|
||||
|
||||
type ApiContent = {
|
||||
local_content_id: string;
|
||||
region_code: string;
|
||||
content_type: ContentType;
|
||||
external_id?: string;
|
||||
title?: string;
|
||||
body: Record<string, unknown>;
|
||||
@@ -43,14 +52,17 @@ function formatDate(value: unknown) {
|
||||
}
|
||||
|
||||
function toContent(item: ApiContent): LocalContent {
|
||||
// 기간은 축제만 있다(eventstartdate/eventenddate) — 관광지·맛집은 상시 정보라 비어 있는 게 정상이다.
|
||||
const start = formatDate(item.body.eventstartdate);
|
||||
const end = formatDate(item.body.eventenddate);
|
||||
const period = [start, end].filter(Boolean).join(' ~ ') || (item.content_type === 2 ? '기간 미정' : '상시');
|
||||
return {
|
||||
id: item.local_content_id,
|
||||
contentType: item.content_type,
|
||||
title: item.title || '제목 없음',
|
||||
region: String(item.body.addr1 || item.region_code),
|
||||
period: [start, end].filter(Boolean).join(' ~ ') || '기간 미정',
|
||||
source: `공공데이터포털 전국문화축제표준데이터 · ${item.external_id ?? '-'}`,
|
||||
period,
|
||||
source: `한국관광공사 TourAPI · ${item.external_id ?? '-'}`,
|
||||
status: item.status,
|
||||
selected: false,
|
||||
displayStart: item.display_start_at,
|
||||
@@ -95,15 +107,24 @@ export function LocalContentPage() {
|
||||
} catch { toast.error('발행하지 못했습니다.'); }
|
||||
};
|
||||
const sync = async () => {
|
||||
const regionCode = window.prompt('내부 지역 코드(예: gunsan)를 입력하세요.', 'gunsan')?.trim();
|
||||
if (!regionCode) return;
|
||||
// ★ 주변정보는 업장 단위(place_contents)다 — 지역 코드가 아니라 사업장 id 로 받는다.
|
||||
// 이 화면의 목록은 아직 지역 캐시(local_contents)를 보여준다. 업장별 목록 화면은 다음 작업이다.
|
||||
const placeId = window.prompt('사업장 ID(place_id)를 입력하세요. 사업장 목록 주소의 /places/ 뒤 값입니다.')?.trim();
|
||||
if (!placeId) return;
|
||||
setSyncing(true);
|
||||
try {
|
||||
const res = await customFetch<{result?: {success?: boolean}; msg?: string; collected?: number; skipped?: number}>({
|
||||
url: '/v1/admin/local-content/sync-festivals', method: 'POST', data: {region_code: regionCode},
|
||||
});
|
||||
const res = await customFetch<{
|
||||
result?: {success?: boolean}; msg?: string;
|
||||
festivals?: number; attractions?: number; restaurants?: number; changed?: boolean;
|
||||
}>({url: `/v1/admin/local-content/place/${placeId}/sync`, method: 'POST'});
|
||||
if (res.result?.success === false) throw new Error(res.msg);
|
||||
toast.success(`${res.collected ?? 0}건 수집 · ${res.skipped ?? 0}건 중복 제외`);
|
||||
// ★ 여행코스(코스)는 2026-09-08부터 수집하지 않는다(반경을 넓혀도 데이터가 거의 없었다) — 표기에서 뺀다.
|
||||
const summary = `축제 ${res.festivals ?? 0} · 관광지 ${res.attractions ?? 0} · 맛집 ${res.restaurants ?? 0}건`;
|
||||
if (!res.changed) {
|
||||
toast.info(`바뀐 내용이 없습니다 (${summary}, TourAPI 원문 그대로).`);
|
||||
} else {
|
||||
toast.success(`${summary} 반영 — 다음 빌드부터 발행본에 실립니다.`);
|
||||
}
|
||||
await load();
|
||||
} catch (error) {
|
||||
toast.error(error instanceof Error ? error.message : '공공데이터 수집에 실패했습니다.');
|
||||
@@ -138,7 +159,7 @@ export function LocalContentPage() {
|
||||
return (
|
||||
<PageContainer
|
||||
title="지역 콘텐츠"
|
||||
description="공공데이터에서 지역 축제를 가져와 검수한 뒤 사장님에게 발행합니다."
|
||||
description="한국관광공사 TourAPI 에서 지역 축제·관광지·맛집을 가져와 자동 발행합니다. 필요하면 여기서 수정하거나 발행을 종료할 수 있습니다."
|
||||
actions={<Button onClick={sync} disabled={syncing}><Download className="size-4" />{syncing ? '수집 중…' : '공공데이터 수집'}</Button>}
|
||||
>
|
||||
<div className="mb-4 grid gap-3 sm:grid-cols-3">
|
||||
@@ -174,6 +195,7 @@ export function LocalContentPage() {
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="mb-1 flex flex-wrap items-center gap-2">
|
||||
<h2 className="text-sm font-semibold">{item.title}</h2>
|
||||
<Badge variant={TYPE_BADGE_VARIANT[item.contentType]}>{TYPE_LABEL[item.contentType]}</Badge>
|
||||
<Badge variant={item.status === 2 ? 'success' : 'warning'}>{STATUS_LABEL[item.status]}</Badge>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-x-4 gap-y-1 text-xs text-muted-foreground">
|
||||
|
||||
Reference in new issue
Block a user