feat(cms): LegalPages collection + migration (MITHOME-88)
CI Pipeline with Test Management / 🧪 Run Tests & Generate Reports (push) Waiting to run
CI Pipeline with Test Management / 🐳 Docker Integration Tests (push) Blocked by required conditions
CI Pipeline with Test Management / 🏗️ Build Docker Image (push) Blocked by required conditions
CI Pipeline with Test Management / 📊 Generate Test Summary (push) Blocked by required conditions
Test Reporting & Gherkin Analysis / 🧪 Run Tests & Generate Reports (push) Waiting to run
Test Reporting & Gherkin Analysis / 📊 Analyze Test Coverage (push) Blocked by required conditions
Test Reporting & Gherkin Analysis / 🔄 Sync with Linear (push) Blocked by required conditions
Test Reporting & Gherkin Analysis / ⚡ Performance Monitoring (push) Blocked by required conditions

Slug-based collection mirroring LegalPageContent (proto/src/content/
types.ts) for the two legal pages (adatvedelem, hasznalati-feltetelek).

- src/collections/LegalPages.ts: slug (unique), title, lastUpdated,
  sections[] (id/title/content). `content` stays a plain textarea, not
  lexical richText — the current frontend
  (src/app/(frontend)/adatvedelem/page.tsx) renders it through a
  hand-rolled "•"/"**bold**" regex converter, not a real Markdown/
  richText parser, matching the same bootstrap-scope call made for
  Contact.gdpr.label in MITHOME-87.
- Registered in payload.config.ts.
- migrate-content-to-payload.ts: added an idempotent upsertLegalPage
  helper (find-by-slug, then update or create — Collections don't have
  Globals' fixed-slug updateGlobal) and seeded both legal pages from
  their existing JSON.

Verified: migration run twice against the real dev MongoDB produced
exactly 2 documents (no duplicates) — confirmed via mongosh. Real
browser: logged into /admin, Legal Pages list shows both entries with
correct titles/slugs, opened the adatvedelem document and the slug/
title/body fields all show the migrated content correctly. build/lint/
tsc/test (58 passed) all clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-09-10 12:16:09 +02:00
co-authored by Claude Sonnet 5
parent 570f4b45e5
commit 17c6d63ae3
3 changed files with 100 additions and 9 deletions
+46 -7
View File
@@ -1,16 +1,18 @@
/**
* MITHOME-87: egyszeri migrációs script — a proto/src/content/pages/*.json
* MITHOME-87/88: egyszeri migrációs script — a proto/src/content/pages/*.json
* + common.json tartalmát átemeli a Payload Globals-ekbe (Home, About,
* Services, Contact, Common) a Local API-n keresztül.
* Services, Contact, Common) és a LegalPages collection-be a Local API-n
* keresztül.
*
* Futtatás (proto/ mappából, futó MongoDB-vel és beállított env-ekkel):
* node --env-file=.env.local --import tsx scripts/migrate-content-to-payload.ts
*
* Idempotens: updateGlobal-t hív, tetszőlegesen többször futtatható —
* mindig a JSON az aktuális "forrás igazság", felülírja a Payload-ban
* lévő korábbi állapotot. NEM törli/nem érinti a JSON fájlokat.
* Idempotens: updateGlobal-t / slug-alapú upsert-et hív, tetszőlegesen
* többször futtatható — mindig a JSON az aktuális "forrás igazság", felül-
* írja a Payload-ban lévő korábbi állapotot. NEM törli/nem érinti a JSON
* fájlokat.
*/
import { getPayload } from 'payload'
import { getPayload, type Payload } from 'payload'
import config from '../src/payload.config'
import homeJson from '../src/content/pages/home.json'
@@ -18,6 +20,8 @@ import aboutJson from '../src/content/pages/about.json'
import servicesJson from '../src/content/pages/services.json'
import contactJson from '../src/content/pages/contact.json'
import commonJson from '../src/content/common.json'
import adatvedelemJson from '../src/content/pages/adatvedelem.json'
import hasznalatiFeltetelekJson from '../src/content/pages/hasznalati-feltetelek.json'
/** string[] -> [{ value: string }] — lásd src/globals/fields/stringArray.ts */
function toStringArray(items: readonly string[]): { value: string }[] {
@@ -76,6 +80,35 @@ function buildServicesData(json: typeof servicesJson) {
}
}
type LegalPageJson = {
title: string
lastUpdated: string
sections: { id: string; title: string; content: string }[]
}
/** 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) {
const existing = await payload.find({
collection: 'legal-pages',
where: { slug: { equals: slug } },
limit: 1,
})
if (existing.docs.length > 0) {
await payload.update({
collection: 'legal-pages',
id: existing.docs[0].id,
data: { slug, ...json },
})
} else {
await payload.create({
collection: 'legal-pages',
data: { slug, ...json },
})
}
}
async function run() {
const payload = await getPayload({ config })
@@ -94,7 +127,13 @@ async function run() {
await payload.updateGlobal({ slug: 'common', data: commonJson })
payload.logger.info('Common global migrálva')
payload.logger.info('MITHOME-87 migráció kész.')
await upsertLegalPage(payload, 'adatvedelem', adatvedelemJson)
payload.logger.info('LegalPages/adatvedelem migrálva')
await upsertLegalPage(payload, 'hasznalati-feltetelek', hasznalatiFeltetelekJson)
payload.logger.info('LegalPages/hasznalati-feltetelek migrálva')
payload.logger.info('MITHOME-87/88 migráció kész.')
process.exit(0)
}