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
@@ -73,10 +73,12 @@ function buildHomeData(json: typeof homeJson) {
|
||||
trustBullets: toStringArray(hero.trustBullets),
|
||||
cta: { primary: toCtaLink(hero.cta.primary), secondary: toCtaLink(hero.cta.secondary) },
|
||||
},
|
||||
about,
|
||||
// MITHOME-138: the JSON `id` is the row key, not the row id.
|
||||
about: { ...about, usps: about.usps.map(({ id, ...usp }) => ({ key: id, ...usp })) },
|
||||
services: {
|
||||
...services,
|
||||
items: services.items.map((item) => ({
|
||||
items: services.items.map(({ id, ...item }) => ({
|
||||
key: id,
|
||||
...item,
|
||||
features: toStringArray(item.features),
|
||||
})),
|
||||
|
||||
@@ -155,8 +155,9 @@ async function importBundle(file: string) {
|
||||
}
|
||||
|
||||
for (const g of globals) {
|
||||
const entry = bundle.globals[g.slug]
|
||||
if (!entry) continue
|
||||
const raw = bundle.globals[g.slug]
|
||||
if (!raw) continue
|
||||
const entry: BundleDoc = { published: upgradeDoc(g.slug, raw.published), ...(raw.draft ? { draft: upgradeDoc(g.slug, raw.draft) } : {}) }
|
||||
const slug = g.slug as GlobalSlug
|
||||
const status = hasDrafts(g) ? { _status: 'published' } : {}
|
||||
for (const locale of LOCALES) {
|
||||
|
||||
@@ -57,7 +57,7 @@ export default async function LocaleLayout({
|
||||
contactEmail={siteConfig.contact.email}
|
||||
footerAddress={common.footer.address}
|
||||
footerCopyright={common.footer.copyright}
|
||||
homeServices={home.services.items.map((item) => ({ id: item.id, title: item.title, icon: item.icon }))}
|
||||
homeServices={home.services.items.map((item) => ({ id: item.key, title: item.title, icon: item.icon }))}
|
||||
locale={locale}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -116,7 +116,7 @@ export default function HomeView({ content: pageContent, partners, locale }: Hom
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 stagger-children">
|
||||
{(pageContent.about.usps ?? []).map((usp, index) => (
|
||||
<div
|
||||
key={usp.id}
|
||||
key={usp.key}
|
||||
className="group text-center p-6 rounded-xl transition-all duration-300 hover-lift animate-fade-in-up"
|
||||
style={{
|
||||
background: 'var(--color-background)',
|
||||
@@ -167,7 +167,7 @@ export default function HomeView({ content: pageContent, partners, locale }: Hom
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-8 max-w-5xl mx-auto">
|
||||
{pageContent.services.items.map((service, index) => (
|
||||
<div
|
||||
key={service.id}
|
||||
key={service.key}
|
||||
className="group card hover-lift"
|
||||
style={{ animationDelay: `${index * 100}ms` }}
|
||||
>
|
||||
|
||||
@@ -30,7 +30,7 @@ export default function ServicesView({ content: pageContent, homeServices, featu
|
||||
<section className="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
|
||||
{homeServices.map((service) => (
|
||||
<div key={service.id} className="bg-white dark:bg-slate-800 rounded-xl shadow-sm border border-gray-200 dark:border-slate-700 p-8 hover:shadow-md transition-shadow">
|
||||
<div key={service.key} className="bg-white dark:bg-slate-800 rounded-xl shadow-sm border border-gray-200 dark:border-slate-700 p-8 hover:shadow-md transition-shadow">
|
||||
<div className="w-16 h-16 bg-blue-100 dark:bg-blue-900/40 rounded-lg flex items-center justify-center mb-6">
|
||||
<span className="text-2xl">{service.icon}</span>
|
||||
</div>
|
||||
|
||||
@@ -55,7 +55,8 @@ export const Home: GlobalConfig = {
|
||||
name: 'usps',
|
||||
type: 'array',
|
||||
fields: [
|
||||
{ name: 'id', type: 'text', required: true },
|
||||
// MITHOME-138: own field; as the row `id` it was the row's primary key.
|
||||
{ name: 'key', type: 'text', required: true, admin: { description: 'Rövid, egyedi azonosító (pl. hosting).' } },
|
||||
{ name: 'title', type: 'text', required: true, localized: true },
|
||||
{ name: 'description', type: 'textarea', required: true, localized: true },
|
||||
{ name: 'icon', type: 'text', required: true },
|
||||
@@ -73,7 +74,8 @@ export const Home: GlobalConfig = {
|
||||
name: 'items',
|
||||
type: 'array',
|
||||
fields: [
|
||||
{ name: 'id', type: 'text', required: true },
|
||||
// MITHOME-138: own field; as the row `id` it was the row's primary key.
|
||||
{ name: 'key', type: 'text', required: true, admin: { description: 'Rövid, egyedi azonosító (pl. hosting).' } },
|
||||
{ name: 'title', type: 'text', required: true, localized: true },
|
||||
{ name: 'description', type: 'textarea', required: true, localized: true },
|
||||
{ name: 'icon', type: 'text', required: true },
|
||||
|
||||
@@ -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,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
/* MITHOME-138: generated by `payload migrate:create`, plus a hand-written backfill in up(). */
|
||||
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
||||
|
||||
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
||||
await db.execute(sql`
|
||||
ALTER TABLE "home_about_usps" ADD COLUMN "key" varchar;
|
||||
ALTER TABLE "home_services_items" ADD COLUMN "key" varchar;
|
||||
ALTER TABLE "_home_v_version_about_usps" ADD COLUMN "key" varchar;
|
||||
ALTER TABLE "_home_v_version_services_items" ADD COLUMN "key" varchar;`)
|
||||
// MITHOME-138 (hand-written backfill): the editable key used to be the row
|
||||
// id itself; in the version tables the original row id is kept in `_uuid`.
|
||||
// The row ids stay, so the page renders the same rows.
|
||||
await db.execute(sql`
|
||||
UPDATE "home_about_usps" SET "key" = "id" WHERE "key" IS NULL;
|
||||
UPDATE "home_services_items" SET "key" = "id" WHERE "key" IS NULL;
|
||||
UPDATE "_home_v_version_about_usps" SET "key" = "_uuid" WHERE "key" IS NULL;
|
||||
UPDATE "_home_v_version_services_items" SET "key" = "_uuid" WHERE "key" IS NULL;`)
|
||||
}
|
||||
|
||||
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
||||
await db.execute(sql`
|
||||
ALTER TABLE "home_about_usps" DROP COLUMN "key";
|
||||
ALTER TABLE "home_services_items" DROP COLUMN "key";
|
||||
ALTER TABLE "_home_v_version_about_usps" DROP COLUMN "key";
|
||||
ALTER TABLE "_home_v_version_services_items" DROP COLUMN "key";`)
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
import * as migration_20260929_202255_initial from './20260929_202255_initial';
|
||||
import * as migration_20260929_213538_home_row_keys from './20260929_213538_home_row_keys';
|
||||
|
||||
export const migrations = [
|
||||
{
|
||||
up: migration_20260929_202255_initial.up,
|
||||
down: migration_20260929_202255_initial.down,
|
||||
name: '20260929_202255_initial'
|
||||
name: '20260929_202255_initial',
|
||||
},
|
||||
{
|
||||
up: migration_20260929_213538_home_row_keys.up,
|
||||
down: migration_20260929_213538_home_row_keys.down,
|
||||
name: '20260929_213538_home_row_keys'
|
||||
},
|
||||
];
|
||||
|
||||
@@ -159,7 +159,8 @@ describe('Payload globals', () => {
|
||||
// MITHOME-113: `result`/`notes` are legal-validation metadata, not copy.
|
||||
// MITHOME-130: a product `name` is a brand, the same in every language.
|
||||
// MITHOME-136: the legal section `anchor` (formerly its row `id`) is shared too.
|
||||
const SHARED_TEXT_FIELDS = new Set(['icon', 'id', 'anchor', 'address', 'slug', 'result', 'notes', 'name'])
|
||||
// MITHOME-138: the Home usps/items `key` (formerly the row `id`) is shared too.
|
||||
const SHARED_TEXT_FIELDS = new Set(['icon', 'id', 'anchor', 'key', 'address', 'slug', 'result', 'notes', 'name'])
|
||||
|
||||
type Node = FieldLike & { localized?: boolean; fields?: Node[] }
|
||||
type Finding = { path: string; type?: string; localized: boolean }
|
||||
|
||||
Reference in New Issue
Block a user