chore: remove MongoDB service, packages and transfer tooling (MITHOME-136)

The staging site runs on PostgreSQL since 2026-09-29. Drop the mongodb
compose service/volume, the mongodb/mongoose/@payloadcms/db-mongodb
packages, the one-off transfer script and its helpers, the mongodump
block in deploy.sh and the Mongo jest mock. Docs updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-10-03 21:16:55 +02:00
co-authored by Claude Sonnet 5.5
parent b3b0347787
commit e14a987bf3
22 changed files with 18 additions and 840 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ function sanitizeInput(input: string): string {
}
// WHY: explicit length caps — the CMS has a body limit but this public endpoint
// does not; without them an arbitrarily large message could be written to Mongo.
// does not; without them an arbitrarily large message could be written to the database.
const MAX_LENGTHS = {
name: 100,
email: 254,
+3 -3
View File
@@ -30,8 +30,8 @@ const { mockLoggerError } = jest.requireMock('@/lib/logger')
// relative specifier at transform time (Jest itself doesn't understand
// tsconfig `paths`), so a `jest.mock('@payload-config', ...)` never actually
// intercepts what route.ts ends up requiring — it silently falls through to
// the real proto/src/payload.config.ts (mongooseAdapter, Users/LegalPages/etc
// imports), which needs a live MongoDB and PAYLOAD_SECRET, exactly what these
// the real proto/src/payload.config.ts (postgresAdapter, Users/LegalPages/etc
// imports), which needs a live PostgreSQL and PAYLOAD_SECRET, exactly what these
// tests avoid. The route only ever passes this value through to the (also
// mocked) getPayload(), so its actual shape doesn't matter here.
jest.mock('../../../payload.config', () => ({ __esModule: true, default: {} }))
@@ -78,7 +78,7 @@ describe('/api/contact Unit Tests', () => {
})
it('returns a server error when persistence fails', async () => {
mockCreate.mockRejectedValue(new Error('MongoDB unavailable'))
mockCreate.mockRejectedValue(new Error('Database unavailable'))
const request = {
headers: new Headers({ 'x-forwarded-for': 'persistence-failure' }),
json: async () => validData,
-101
View File
@@ -1,101 +0,0 @@
import type { Field } from 'payload'
import { bundleCounts, localeData, upgradeDoc } from './content-transfer'
const FIELDS: Field[] = [
{ name: 'name', type: 'text' },
{ name: 'title', type: 'text', localized: true },
{
name: 'hero',
type: 'group',
fields: [
{ name: 'title', type: 'text', localized: true },
{ name: 'icon', type: 'text' },
],
},
{
name: 'items',
type: 'array',
fields: [
{ name: 'label', type: 'text', localized: true },
{ name: 'order', type: 'number' },
],
},
{ name: 'paragraphs', type: 'array', localized: true, fields: [{ name: 'value', type: 'text' }] },
{ type: 'row', fields: [{ name: 'result', type: 'text' }] },
{ name: 'logo', type: 'upload', relationTo: 'media' },
]
const DOC = {
id: 'old-doc',
_id: 'old-doc',
__v: 0,
_status: 'published',
updatedAt: '2026-09-29T10:00:00.000Z',
createdAt: '2026-09-01T08:00:00.000Z',
name: 'mIT Start',
title: { hu: 'Cím', en: 'Title' },
hero: { title: { hu: 'Hős', en: 'Hero' }, icon: '🔥' },
items: [{ id: 'row1', label: { hu: 'Egy', en: 'One' }, order: 1 }],
paragraphs: { hu: [{ id: 'p1', value: 'Első' }, { id: 'p2', value: 'Második' }], en: [{ id: 'p3', value: 'First' }] },
result: 'ok',
logo: { id: 'old-media', filename: 'logo.png' },
}
describe('content transfer (MITHOME-136)', () => {
it('should split a locale-all document into Hungarian data', () => {
expect(localeData(FIELDS, DOC, 'hu')).toEqual({
name: 'mIT Start',
title: 'Cím',
hero: { title: 'Hős', icon: '🔥' },
items: [{ id: 'row1', label: 'Egy', order: 1 }],
paragraphs: [{ id: 'p1', value: 'Első' }, { id: 'p2', value: 'Második' }],
result: 'ok',
logo: 'old-media',
createdAt: '2026-09-01T08:00:00.000Z',
})
})
it('should keep array row ids so the English update hits the same rows', () => {
const en = localeData(FIELDS, DOC, 'en')
expect(en.items).toEqual([{ id: 'row1', label: 'One', order: 1 }])
expect(en.paragraphs).toEqual([{ id: 'p3', value: 'First' }])
expect(en.title).toBe('Title')
})
it('should map upload ids to the new documents', () => {
const ids = new Map([['old-media', 'new-media']])
expect(localeData(FIELDS, DOC, 'hu', ids).logo).toBe('new-media')
})
it('should drop system fields and leave missing fields out', () => {
const data = localeData(FIELDS, { name: 'x', _status: 'draft', globalType: 'home' }, 'hu')
expect(data).toEqual({ name: 'x' })
})
it('should count the documents of a bundle', () => {
expect(
bundleCounts({
exportedAt: '',
source: '',
globals: { home: { published: {} } },
collections: { partners: [{ published: {} }, { published: {} }] },
files: {},
}),
).toEqual({ partners: 2, 'global:home': 1 })
})
it('should move the legal section anchor out of the row id, unique per page', () => {
const doc = { slug: 'adatvedelem', sections: [{ id: 'bevezetes', title: { hu: 'Bevezetés' } }] }
expect(upgradeDoc('legal-pages', doc).sections).toEqual([
{ id: 'adatvedelem-bevezetes', anchor: 'bevezetes', title: { hu: 'Bevezetés' } },
])
expect(upgradeDoc('legal-pages', upgradeDoc('legal-pages', doc))).toEqual(upgradeDoc('legal-pages', doc))
expect(upgradeDoc('partners', doc)).toBe(doc)
})
it('should move the Home usps/items key out of the row id, keeping the row id', () => {
const home = { about: { usps: [{ id: 'egyszeru', icon: '🎯' }] }, services: { items: [{ id: 'hosting' }] } }
const upgraded = upgradeDoc('home', home) as { about: { usps: unknown[] }; services: { items: unknown[] } }
expect(upgraded.about.usps).toEqual([{ id: 'egyszeru', key: 'egyszeru', icon: '🎯' }])
expect(upgraded.services.items).toEqual([{ id: 'hosting', key: 'hosting' }])
})
})
-112
View File
@@ -1,112 +0,0 @@
/**
* MITHOME-136: pure helpers of the one-off MongoDB → PostgreSQL content
* transfer (scripts/transfer-content.ts).
*
* The export reads every document with `locale: 'all'`, so each localized
* field arrives as `{ hu, en }`. Payload writes one locale at a time, so the
* import splits a document into per-locale data using the field config:
* localized fields take the locale's value, groups/unnamed rows recurse,
* array rows keep their ids (the English update must hit the same rows), and
* upload/relationship ids are mapped from the old to the new id.
*/
import type { Field } from 'payload'
export type Locale = 'hu' | 'en'
type Data = Record<string, unknown>
export type IdMap = Map<string, string>
const SYSTEM_KEYS = new Set(['id', '_id', '__v', 'globalType', 'updatedAt', '_status'])
const isObject = (value: unknown): value is Data =>
typeof value === 'object' && value !== null && !Array.isArray(value)
function mapId(value: unknown, ids: IdMap): unknown {
if (value === null || value === undefined) return value
const id = isObject(value) ? value.id : value
return typeof id === 'string' ? (ids.get(id) ?? id) : id
}
function splitFields(fields: readonly Field[], source: Data, locale: Locale, ids: IdMap, out: Data): Data {
for (const field of fields) {
if (!('name' in field) || !field.name) {
// row / collapsible: unnamed wrappers keep their fields on the same level
if ('fields' in field) splitFields(field.fields, source, locale, ids, out)
continue
}
if (!(field.name in source)) continue
const raw = source[field.name]
const value = 'localized' in field && field.localized && isObject(raw) ? raw[locale] : raw
if (field.type === 'group' && isObject(value)) {
out[field.name] = splitFields(field.fields, value, locale, ids, {})
} else if (field.type === 'array' && Array.isArray(value)) {
out[field.name] = value.map((row) =>
isObject(row) ? { ...(row.id ? { id: row.id } : {}), ...splitFields(field.fields, row, locale, ids, {}) } : row,
)
} else if (field.type === 'upload' || field.type === 'relationship') {
out[field.name] = Array.isArray(value) ? value.map((v) => mapId(v, ids)) : mapId(value, ids)
} else {
out[field.name] = value
}
}
return out
}
/**
* Shape changes between the MongoDB schema and the current one, applied to an
* exported document before it is split by locale.
* - legal-pages: the section anchor was the array row `id`; it is now the
* `anchor` field, and the row id must be unique across all pages (it is a
* table-wide primary key in PostgreSQL), so it becomes `<slug>-<anchor>`.
* - home (global): the usps/items row `id` was the editable key; it is now the
* `key` field (MITHOME-138). The row id stays, so both locales hit the same row.
*/
const withKey = (rows: unknown) =>
Array.isArray(rows)
? rows.map((row) => (isObject(row) && typeof row.id === 'string' && !('key' in row) ? { ...row, key: row.id } : row))
: rows
export function upgradeDoc(collection: string, doc: Data): Data {
if (collection === 'home') {
const about = isObject(doc.about) ? { ...doc.about, usps: withKey(doc.about.usps) } : doc.about
const services = isObject(doc.services) ? { ...doc.services, items: withKey(doc.services.items) } : doc.services
return { ...doc, about, services }
}
if (collection !== 'legal-pages' || !Array.isArray(doc.sections)) return doc
return {
...doc,
sections: doc.sections.map((section) =>
isObject(section) && typeof section.id === 'string' && !('anchor' in section)
? { ...section, id: `${doc.slug}-${section.id}`, anchor: section.id }
: section,
),
}
}
/** The data of one locale, ready for `create`/`update` with that `locale`. */
export function localeData(fields: readonly Field[], doc: Data, locale: Locale, ids: IdMap = new Map()): Data {
const out = splitFields(fields, doc, locale, ids, {})
for (const key of SYSTEM_KEYS) delete out[key]
// Keep the original creation time (contact submission retention).
if (typeof doc.createdAt === 'string') out.createdAt = doc.createdAt
return out
}
/** Count documents per collection/global in an export bundle. */
export function bundleCounts(bundle: TransferBundle): Record<string, number> {
const counts: Record<string, number> = {}
for (const [slug, docs] of Object.entries(bundle.collections)) counts[slug] = docs.length
for (const slug of Object.keys(bundle.globals)) counts[`global:${slug}`] = 1
return counts
}
export type BundleDoc = { published: Data; draft?: Data }
export type TransferBundle = {
exportedAt: string
source: string
globals: Record<string, BundleDoc>
collections: Record<string, BundleDoc[]>
/** Upload files by filename, base64 — the bundle is self-contained. */
files: Record<string, { mimeType: string; base64: string }>
}
+2 -2
View File
@@ -2,7 +2,7 @@
* MITHOME-96 — Payload collection/global config tesztek.
*
* WHY nem a teljes payload.config.ts-t importáljuk: az a valódi `payload` és
* `@payloadcms/db-mongodb` csomagokat importálja értékként (nem csak
* `@payloadcms/db-postgres` csomagokat importálja értékként (nem csak
* típusként), amik ESM-only, natív node_modules-forrást futtatnak — Jest
* (a next/jest transzformmal is) nem tudja lefordítani őket anélkül, hogy a
* teljes payload-függőségi fát is a transformIgnorePatterns kivételévé
@@ -10,7 +10,7 @@
* module` a payload csomag saját forrásából). Az egyes Collection/Global
* fájlok viszont csak `import type` formában hivatkoznak a `payload`
* csomagra — ez típus-only import, a build kitörli, így ezek a fájlok
* önmagukban, gyors unit tesztként importálhatók, élő MongoDB/PAYLOAD_SECRET
* önmagukban, gyors unit tesztként importálhatók, élő PostgreSQL/PAYLOAD_SECRET
* nélkül. Ez fedi le a ticket "Payload config tesztek" részét; a Local API
* ellen futó, élő adatbázist igénylő tesztek külön (integrációs) fájlban
* vannak — lásd src/__tests__/payload-local-api.test.ts.
+1 -1
View File
@@ -3,7 +3,7 @@
*
* WHY separate: the site runs on PostgreSQL (src/payload.config.ts), but the
* one-off content transfer (scripts/transfer-content.ts) must read the same
* collections and globals through the MongoDB adapter. Both configs are built
* collections and globals through the database adapter. Both configs are built
* from this object, so the content model cannot drift between them.
*/
import path from 'path'