feat: Add fresh database setup script and media handling improvements
- 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.
This commit is contained in:
@@ -3,19 +3,10 @@ import 'dotenv/config'
|
||||
import config from '@payload-config'
|
||||
import crypto from 'crypto'
|
||||
import { getPayload, type Payload } from 'payload'
|
||||
import { mediaByFilename } from './mediaByFilename'
|
||||
|
||||
import { netzwerkContent } from '@/spa/netzwerkContent'
|
||||
|
||||
const mediaByFilename = async (payload: Payload, filename: string) => {
|
||||
const result = await payload.find({
|
||||
collection: 'media',
|
||||
limit: 1,
|
||||
pagination: false,
|
||||
where: { filename: { equals: filename } },
|
||||
})
|
||||
return result.docs[0]?.id
|
||||
}
|
||||
|
||||
const safeRemoteName = (url: string) => {
|
||||
const parsed = new URL(url)
|
||||
const ext = parsed.pathname.split('/').pop()?.includes('.') ? `.${parsed.pathname.split('.').pop()}` : '.jpg'
|
||||
@@ -39,6 +30,11 @@ const itemsWithImageUploads = async <T extends { image?: string }>(payload: Payl
|
||||
}),
|
||||
)
|
||||
|
||||
const partnersForPayload = netzwerkContent.partners.items.map(({ id, ...partner }) => ({
|
||||
...partner,
|
||||
stableId: id,
|
||||
}))
|
||||
|
||||
async function main() {
|
||||
const payload = await getPayload({ config })
|
||||
|
||||
@@ -89,11 +85,16 @@ async function main() {
|
||||
...sponsoringContent,
|
||||
image: sponsoringImage,
|
||||
},
|
||||
partners: {
|
||||
...netzwerkContent.partners,
|
||||
items: partnersForPayload,
|
||||
},
|
||||
},
|
||||
} as never,
|
||||
})
|
||||
|
||||
payload.logger.info(`Preloaded Netzwerk CMS fields for page ${page.id}`)
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
|
||||
Reference in New Issue
Block a user