Files
klz-cables.com/.pnpm-store/v10/files/3c/9bf449fad5842b0f857a66834ef3afc35f429984985a5a191982924b6750e80dda809d291ea5fa26f6c720e0b8294ee25339eb6981ddad3df0282dd7aca3ca
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

54 lines
1.9 KiB
Plaintext

import { toSnakeCase } from '../shared.js';
/**
* Migrates main global document from _status to per-locale status object
*/ export async function migrateMainGlobalStatus({ db, globalSlug, locales, payload, sql, versionsTable }) {
const globalTable = toSnakeCase(globalSlug);
const globalLocalesTable = `${globalTable}_locales`;
payload.logger.info({
msg: `Migrating main global locales for: ${globalLocalesTable}`
});
// For each locale, get the latest version status
for (const locale of locales){
const latestVersionStatus = await db.execute({
drizzle: db.drizzle,
sql: sql`
SELECT l.version__status as _status
FROM ${sql.identifier(versionsTable)} v
JOIN ${sql.raw(`${versionsTable}_locales`)} l ON l._parent_id = v.id
WHERE l._locale = ${locale}
ORDER BY v.created_at DESC
LIMIT 1
`
});
const status = latestVersionStatus.rows[0]?._status || 'draft';
// Get the global document ID from the globals table
const globalDoc = await db.execute({
drizzle: db.drizzle,
sql: sql`
SELECT id FROM ${sql.identifier(globalTable)} LIMIT 1
`
});
if (globalDoc.rows.length === 0) {
payload.logger.warn({
msg: `No global document found for ${globalSlug}, skipping`
});
continue;
}
const globalId = globalDoc.rows[0].id;
// Update the global's locales table with this status
await db.execute({
drizzle: db.drizzle,
sql: sql`
UPDATE ${sql.identifier(globalLocalesTable)}
SET _status = ${status}
WHERE _parent_id = ${globalId}
AND _locale = ${locale}
`
});
}
payload.logger.info({
msg: 'Migrated global document'
});
}
//# sourceMappingURL=migrateMainGlobal.js.map