fix(cms): Home usps/items key is its own field, not the row primary key (MITHOME-138)
CI Pipeline with Test Management / 🧪 Run Tests & Generate Reports (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 🧪 Run Tests & Generate Reports (push) Canceled after 0s
CI Pipeline with Test Management / 🐳 Docker Integration Tests (push) Canceled after 0s
CI Pipeline with Test Management / 🏗️ Build Docker Image (push) Canceled after 0s
CI Pipeline with Test Management / 📊 Generate Test Summary (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 📊 Analyze Test Coverage (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 🔄 Sync with Linear (push) Canceled after 0s
Test Reporting & Gherkin Analysis / ⚡ Performance Monitoring (push) Canceled after 0s
CI Pipeline with Test Management / 🧪 Run Tests & Generate Reports (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 🧪 Run Tests & Generate Reports (push) Canceled after 0s
CI Pipeline with Test Management / 🐳 Docker Integration Tests (push) Canceled after 0s
CI Pipeline with Test Management / 🏗️ Build Docker Image (push) Canceled after 0s
CI Pipeline with Test Management / 📊 Generate Test Summary (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 📊 Analyze Test Coverage (push) Canceled after 0s
Test Reporting & Gherkin Analysis / 🔄 Sync with Linear (push) Canceled after 0s
Test Reporting & Gherkin Analysis / ⚡ Performance Monitoring (push) Canceled after 0s
The editable id of the Home usps/items rows was also the row's primary key in PostgreSQL (a duplicate would fail to save; new rows needed a manual id). It is now the `key` field; migration 20260929_213538_home_row_keys adds the column and backfills it (main tables from id, version tables from _uuid). Tried on the staging pg_dump: keys backfilled, second run no-op, all 14 public pages unchanged. React keys use `key`; the transfer upgrades old bundles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
244553a665
commit
4a263586aa
@@ -92,4 +92,10 @@ describe('content transfer (MITHOME-136)', () => {
|
||||
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' }])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -58,8 +58,20 @@ function splitFields(fields: readonly Field[], source: Data, locale: Locale, ids
|
||||
* - 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,
|
||||
|
||||
Reference in New Issue
Block a user