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>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ef93cec935
commit
0eb6594acc
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 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')
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as migration_20260929_localize_globals from './20260929_localize_globals'
|
||||
import * as migration_20260929_cta_page_links from './20260929_cta_page_links'
|
||||
import * as migration_20260929_localize_legal_pages from './20260929_localize_legal_pages'
|
||||
|
||||
/**
|
||||
* Payload migrations, in order. Passed to `mongooseAdapter({ prodMigrations })`
|
||||
@@ -17,4 +18,10 @@ export const migrations = [
|
||||
down: migration_20260929_cta_page_links.down,
|
||||
name: '20260929_cta_page_links',
|
||||
},
|
||||
{
|
||||
// MITHOME-112 — LegalPages counterpart of the globals locale migration.
|
||||
up: migration_20260929_localize_legal_pages.up,
|
||||
down: migration_20260929_localize_legal_pages.down,
|
||||
name: '20260929_localize_legal_pages',
|
||||
},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user