[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:
minaChoiandClaude Opus 5 committed 2026-09-09 17:08:02 +09:00
1 parent 7bbeb068a8
commit 64ce467f21
189 files changed
+13374 -5023

No files matched your search

+1
View File
@@ -4,5 +4,6 @@ export * from './head';
export * from './robots';
export * from './sitemap';
export * from './directory';
export * from './security';
export * from './llms';
export * from './verify';
+38 -4
View File
@@ -1,6 +1,7 @@
import {
LinkChannel,
PlaceCategory,
displayFactLabel,
factBool,
factValue,
joinUrl,
@@ -68,7 +69,9 @@ function amenityFeatures(facts: FactEntry[]): Json[] {
.map((fact) =>
compact({
'@type': 'LocationFeatureSpecification',
name: fact.label,
// ★ 화면과 **같은** 이름표를 쓴다. 화면은 "주차 | 가능" 인데 여기만 "주차 가능" 이면
// 발행 게이트가 "구조화 데이터가 화면 값과 다르다"로 막는다 — 실제로 막혔다.
name: displayFactLabel(fact),
value: factBool(facts, fact.key) ?? undefined,
}),
);
@@ -178,7 +181,10 @@ export function businessJsonLd(payload: SitePayload): Json {
return compact({
'@context': 'https://schema.org',
'@type': SCHEMA_TYPE[place.category] ?? 'LocalBusiness',
// ★ 특화 타입 하나만 쓰면 `LodgingBusiness` 를 LocalBusiness 로 못 펴는 파서가 있다.
// 상위 타입을 같이 적어야 "이 페이지에 사업장 엔티티가 있다"가 문자열 대조로도 잡힌다.
// (schema.org 상 중복이지 모순이 아니다 — LodgingBusiness ⊂ LocalBusiness ⊂ Organization)
'@type': [SCHEMA_TYPE[place.category] ?? 'LocalBusiness', 'LocalBusiness', 'Organization'],
'@id': `${siteUrl(payload)}#business`,
name: place.name,
alternateName: place.englishName,
@@ -380,17 +386,44 @@ export function webPageJsonLd(
inLanguage: 'ko-KR',
isPartOf: {'@id': `${siteUrl(payload)}#website`},
about: {'@id': `${siteUrl(payload)}#business`},
// ★ "누가 썼나" 가 비어 있으면 E-E-A-T 채점에서 통째로 0점이다. 이 페이지의 모든 문장은
// 사업자가 확인한 값이므로 저자·발행자는 사업장 자신이다 — 사람 이름을 지어내지 않는다.
author: {'@id': `${siteUrl(payload)}#business`},
publisher: {'@id': `${siteUrl(payload)}#business`},
datePublished: payload.site.publishedAt,
dateModified: payload.site.updatedAt,
// 음성 답변이 읽어 갈 자리. 상호가 든 h1 과 "예약 전 확인" 단정문 문단이다.
speakable: {
'@type': 'SpeakableSpecification',
cssSelector: ['h1', '#summary p'],
},
});
}
/**
* 빵부스러기.
*
* ★ 예전에는 "한 장짜리 사이트라 자기 자신뿐"이라며 뺐다. 하지만 이 사이트는 오리진 루트
* 아래 `/s/<slug>` 에 있어서 **상위가 실제로 존재한다** — 홈 → 이 업소. 두 칸짜리라도
* 크롤러에게 "이 URL 이 이 호스트의 어디에 속하는지"를 알려 주는 값이 있다.
*/
export function breadcrumbJsonLd(payload: SitePayload): Json {
const origin = payload.site.origin.replace(/\/+$/, '');
return {
'@context': 'https://schema.org',
'@type': 'BreadcrumbList',
'@id': `${siteUrl(payload)}#breadcrumb`,
itemListElement: [
{'@type': 'ListItem', position: 1, name: '홈', item: `${origin}/`},
{'@type': 'ListItem', position: 2, name: payload.place.name, item: siteUrl(payload)},
],
};
}
/** 한 페이지에 실릴 JSON-LD 전부. null 은 걸러진다. */
/**
* 이 사이트가 내보내는 구조화 데이터 전부.
*
* ★ 사이트가 한 장이라 BreadcrumbList 를 뺐다 — 상위 페이지가 없는 곳의 빵부스러기는
* 자기 자신 하나뿐이라 아무 정보도 주지 않는다.
* ★ FAQPage 는 조건 없이 싣는다. 예전에는 페이지마다 실을지 골랐는데, 이제 한 장이라
* FAQ 가 있으면 그 한 장에 있는 것이다.
*/
@@ -402,6 +435,7 @@ export function collectJsonLd(
businessJsonLd(payload),
websiteJsonLd(payload),
webPageJsonLd(payload, page),
breadcrumbJsonLd(payload),
payload.faqs.length > 0 ? faqJsonLd(payload) : null,
].filter((node): node is Json => node !== null);
}
+61 -5
View File
@@ -1,7 +1,7 @@
import {
PlaceCategory,
factValue,
joinUrl,
selectPublishable,
type SitePayload,
} from '@o2o/shared';
@@ -51,6 +51,17 @@ export function primaryImage(payload: SitePayload) {
* 형용사를 붙이지 않는다 — 확인된 값이 그대로 문장이 된다.
*/
export function factualSummary(payload: SitePayload): string {
return factSentences(payload).join(' ');
}
/**
* 확인된 fact 를 문장 단위로 쪼개 돌려준다.
*
* ★ 조각으로 돌려주는 이유: description 은 짧아도 감점이다(권장 50~160자).
* 사장님이 쓴 한 줄 소개가 39자면 뒤에 사실 문장을 하나씩 붙여 길이를 채워야 하는데,
* 통짜 문자열이면 어디서 끊어 붙일지 알 수 없다.
*/
function factSentences(payload: SitePayload): string[] {
const {place, facts} = payload;
const parts: string[] = [];
@@ -76,7 +87,7 @@ export function factualSummary(payload: SitePayload): string {
if (place.phone) parts.push(`문의 ${place.phone}.`);
return parts.join(' ');
return parts;
}
/** 160자 안쪽으로 줄인다. 단어 중간에서 자르지 않는다. */
@@ -87,12 +98,57 @@ function clamp(text: string, max = 160): string {
return `${(lastSpace > max * 0.6 ? cut.slice(0, lastSpace) : cut).trimEnd()}…`;
}
/**
* description 을 권장 길이(50~160자)로 맞춘다.
*
* ★ 짧은 것도 감점이다. 사장님의 한 줄 소개는 대개 30~40자라 그대로 내보내면
* "39자 — 권장 50~160자" 로 걸린다. 지어내서 늘리지 않고, 이미 확인된 fact 문장을
* 50자를 넘을 때까지 하나씩 붙인다. 소개가 이미 50자를 넘으면 손대지 않는다.
*/
function describe(payload: SitePayload, min = 50): string {
const summary = payload.narrative.summary?.trim();
const parts: string[] = [];
if (summary) parts.push(/[.!?。]$/.test(summary) ? summary : `${summary}.`);
for (const sentence of factSentences(payload)) {
if (parts.join(' ').length >= min) break;
if (!parts.some((part) => part.includes(sentence))) parts.push(sentence);
}
return clamp(parts.join(' '));
}
/**
* 사람이 검색창에 치는 업종어. "군산 숙소" 처럼 상호를 모르는 질의에 걸리는 자리다.
* 홍보어(맛집·명소)는 쓰지 않는다 — 확인할 수 없는 주장이다.
*/
const CATEGORY_WORD: Record<PlaceCategory, string> = {
[PlaceCategory.LODGING]: '숙소',
[PlaceCategory.CAFE]: '카페',
[PlaceCategory.RESTAURANT]: '음식점',
[PlaceCategory.CLINIC]: '의원',
};
/**
* `<상호> · <지역> <업종>`.
*
* ★ `<상호> · <시군구>` 였다. "스테이,머뭄 · 군산시" 는 12자인데 Bing 웹마스터도구가
* **15자 미만을 Error(Title too short)** 로 잡는다. 광역시도와 업종어를 같이 실어
* 길이도 채우고 "군산 숙소" 같은 질의에도 걸리게 한다.
*/
function homeTitle(payload: SitePayload): string {
const {place} = payload;
const region = place.addressRegion && place.addressRegion !== localName(payload)
? place.addressRegion
: undefined;
const where = [region, localName(payload), CATEGORY_WORD[place.category]].filter(Boolean).join(' ');
return [place.name, where].filter(Boolean).join(' · ');
}
export function homeMeta(payload: SitePayload): PageMeta {
const image = primaryImage(payload);
return {
// 제목에 지역을 넣는다 — "애월 스테이" 같은 지역 질의에 걸리는 자리다.
title: [payload.place.name, localName(payload)].filter(Boolean).join(' · '),
description: clamp(payload.narrative.summary ?? factualSummary(payload)),
title: homeTitle(payload),
description: describe(payload),
canonical: url(payload),
ogImage: image?.url,
ogImageAlt: image?.alt,
+41
View File
@@ -0,0 +1,41 @@
/**
* `/.well-known/security.txt` (RFC 9116).
*
* ★ 왜 굽나
* 지금은 이 경로가 없어서 nginx 의 SPA 폴백이 사장님 앱 index.html 을 200 으로 준다.
* 진단 도구는 200 을 받고 "security.txt 는 있는데 Contact·Expires 가 없다"로 읽는다 —
* 404 보다 나쁜 상태다. 파일을 진짜로 놓아 규격대로 답하게 한다.
*
* ★ Expires 는 규격상 **필수**이고 지나면 파일이 무효다. 그래서 굽는 시점 기준으로 다시
* 계산한다 — 발행할 때마다 갱신되므로 사람이 손대야 하는 날짜가 코드에 남지 않는다.
* 1년이 아니라 180일인 이유: 규격 권고가 "1년 이내"고, 반년이면 발행이 뜸한 호스트도
* 만료 전에 한 번은 다시 굽힌다.
*/
const EXPIRES_DAYS = 180;
export interface SecurityTxtOptions {
/** `mailto:` 또는 `https:` URL. 없으면 호스트의 security@ 주소로 만든다. */
contact?: string;
/** 굽는 시각. 테스트가 고정값을 넣는다. */
now?: Date;
}
export function renderSecurityTxt(origin: string, options: SecurityTxtOptions = {}): string {
const base = origin.replace(/\/+$/, '');
const host = base.replace(/^https?:\/\//, '');
const now = options.now ?? new Date();
const expires = new Date(now.getTime() + EXPIRES_DAYS * 24 * 60 * 60 * 1000);
const contact = (options.contact ?? '').trim() || `mailto:security@${host}`;
return [
`# ${host} — 취약점 제보 창구 (RFC 9116)`,
`# 이 파일은 발행할 때마다 다시 구워진다. Expires 는 굽는 날 + ${EXPIRES_DAYS}일이다.`,
'',
`Contact: ${contact}`,
`Expires: ${expires.toISOString()}`,
'Preferred-Languages: ko, en',
`Canonical: ${base}/.well-known/security.txt`,
'',
].join('\n');
}