Files
websitedev/proto/src/migrations/20260929_localize_legal_pages.ts
T
Do SikiandClaude Opus 5.5 0eb6594acc feat(cms): localize legal pages with a lossless migration (MITHOME-112)
Legal page title, last-updated text and section titles/contents become
localized; slug and section ids stay shared. A Payload migration wraps
existing values into { hu: value } on every legal page and its whole
version history, like the globals migration (MITHOME-111).

The migration helper now handles collections as well as globals
(rewriteDocs) and can scope version rewrites to the latest working copy,
which the upcoming English import needs. Migration tests share an
in-memory Mongo fake that honours query filters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 10:54:44 +02:00

30 lines
1.4 KiB
TypeScript

/**
* MITHOME-112: a LegalPages mezők utólagos `localized: true` jelölése után a
* meglévő értékeket `{ hu: érték }` alakba csomagolja — minden jogi oldalon
* és a teljes verziótörténetben. Ugyanaz a minta, mint a Globaloknál
* (MITHOME-111, 20260929_localize_globals.ts); idempotens.
*/
import type { MigrateDownArgs, MigrateUpArgs } from '@payloadcms/db-mongodb'
import { LegalPages } from '../collections/LegalPages'
import { collectLocalizedPaths, topLevelKeys, unwrapLocalized, wrapLocalized } from '../lib/localize-paths'
import { rewriteDocs } from '../lib/migrate-global-docs'
const PATHS = collectLocalizedPaths(LegalPages.fields as never)
const TARGET = { kind: 'collection', slug: LegalPages.slug } as const
async function migrate(args: MigrateUpArgs | MigrateDownArgs, direction: 'up' | 'down') {
const transform = direction === 'up' ? wrapLocalized : unwrapLocalized
const changed = await rewriteDocs(args, TARGET, topLevelKeys(PATHS), (data) => transform(data, PATHS))
args.payload.logger.info(`MITHOME-112 locale migration: ${LegalPages.slug} — ${changed} value(s) rewritten`)
}
export async function up(args: MigrateUpArgs): Promise<void> {
await migrate(args, 'up')
}
/** TRADEOFF: drops every non-hu value — restore from a DB dump instead if possible. */
export async function down(args: MigrateDownArgs): Promise<void> {
await migrate(args, 'down')
}