- Introduced a new script for setting up a fresh database with ordered migration tasks. - Added a utility function to find media by filename, improving media handling in various scripts. - Updated preload scripts to utilize the new media fetching utility. - Refactored datenschutz, impressum, and mitglied-werden fields to use stable IDs and anchor IDs. - Enhanced home and network pages to accommodate new field structures. - Added new preload script for global CMS settings. - Improved code readability and organization across multiple files.
55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import 'dotenv/config'
|
|
|
|
import config from '@payload-config'
|
|
import { getPayload, type Payload } from 'payload'
|
|
import { mediaByFilename } from './mediaByFilename'
|
|
|
|
import { preistraegerDetailContent } from '@/spa/preistraegerDetailContent'
|
|
|
|
async function main() {
|
|
const payload = await getPayload({ config })
|
|
const [fallbackImage, sideImage] = await Promise.all([
|
|
mediaByFilename(payload, preistraegerDetailContent.fallbackImageFilename),
|
|
mediaByFilename(payload, preistraegerDetailContent.sideImage.imageFilename),
|
|
])
|
|
const { fallbackImageFilename: _fallbackImageFilename, ...detailContent } = preistraegerDetailContent
|
|
const { imageFilename: _sideImageFilename, ...sideImageContent } = preistraegerDetailContent.sideImage
|
|
|
|
const winners = await payload.find({
|
|
collection: 'preistraeger',
|
|
draft: true,
|
|
overrideAccess: true,
|
|
pagination: false,
|
|
limit: 1000,
|
|
})
|
|
|
|
await Promise.all(
|
|
winners.docs.map((winner) =>
|
|
payload.update({
|
|
collection: 'preistraeger',
|
|
id: winner.id,
|
|
overrideAccess: true,
|
|
context: { disableRevalidate: true },
|
|
data: {
|
|
detailPage: {
|
|
...detailContent,
|
|
fallbackImage,
|
|
sideImage: {
|
|
...sideImageContent,
|
|
image: sideImage,
|
|
},
|
|
},
|
|
} as never,
|
|
}),
|
|
),
|
|
)
|
|
|
|
payload.logger.info(`Preloaded Preisträger detail CMS fields for ${winners.docs.length} records`)
|
|
process.exit(0)
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error)
|
|
process.exit(1)
|
|
})
|