feat(cms): MongoDB → PostgreSQL content transfer; fix two schema issues it found (MITHOME-136)

- scripts/transfer-content.ts: export (shared config + MongoDB adapter,
  locale 'all', drafts, upload files) and import (PostgreSQL, one transaction,
  refuses a non-empty target); pure helpers in src/lib/content-transfer.ts
- LegalPages: the section anchor is its own field; as the array row id it was
  a table-wide primary key in PostgreSQL and the two pages collided
- Products.status: own enumName; the default name equalled the drafts
  _status enum, so only draft/published were accepted
- baseline migration regenerated

Verified on a staging copy (disposable MongoDB + PostgreSQL on llmdev): counts
match, all 14 public pages (hu/en) render identical text, partner logo loads,
second import writes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-09-29 22:27:11 +02:00
co-authored by Claude Opus 5.5
parent e3ec6a9ac3
commit a68fb94b61
14 changed files with 500 additions and 50 deletions
+7 -2
View File
@@ -142,6 +142,11 @@ type LegalPageJson = {
sections: { id: string; title: string; content: string }[]
}
/** MITHOME-136: the JSON section `id` is the section anchor. */
function toLegalData({ sections, ...rest }: LegalPageJson) {
return { ...rest, sections: sections.map(({ id, ...section }) => ({ anchor: id, ...section })) }
}
/** Collections have no per-document "known slug" API like Globals do —
* find-by-slug, then update or create. Idempotent across re-runs. */
async function upsertLegalPage(payload: Payload, slug: string, json: LegalPageJson) {
@@ -155,12 +160,12 @@ async function upsertLegalPage(payload: Payload, slug: string, json: LegalPageJs
await payload.update({
collection: 'legal-pages',
id: existing.docs[0].id,
data: { slug, ...json, _status: 'published' },
data: { slug, ...toLegalData(json), _status: 'published' },
})
} else {
await payload.create({
collection: 'legal-pages',
data: { slug, ...json, _status: 'published' },
data: { slug, ...toLegalData(json), _status: 'published' },
})
}
}