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:
116
src/scripts/setup-fresh-database.ts
Normal file
116
src/scripts/setup-fresh-database.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import 'dotenv/config'
|
||||
|
||||
import config from '@payload-config'
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { getPayload } from 'payload'
|
||||
|
||||
const orderedScripts = [
|
||||
{
|
||||
label: 'Import media assets',
|
||||
path: 'src/scripts/migrate-spa-media.ts',
|
||||
},
|
||||
{
|
||||
label: 'Create base pages, posts, events, and Preisträger records',
|
||||
path: 'src/scripts/migrate-spa-pages.ts',
|
||||
},
|
||||
{
|
||||
label: 'Store header, footer, and site settings defaults',
|
||||
path: 'src/scripts/preload-globals-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload detail page copy for blog posts',
|
||||
path: 'src/scripts/preload-blog-detail-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload detail page copy for events',
|
||||
path: 'src/scripts/preload-event-detail-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload detail page copy for Preisträger',
|
||||
path: 'src/scripts/preload-preistraeger-detail-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload home page',
|
||||
path: 'src/scripts/preload-home-page-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload about page',
|
||||
path: 'src/scripts/preload-about-page-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload contact page',
|
||||
path: 'src/scripts/preload-contact-page-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload Datenschutz page',
|
||||
path: 'src/scripts/preload-datenschutz-page-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload formular upload page',
|
||||
path: 'src/scripts/preload-formular-upload-page-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload Impressum page',
|
||||
path: 'src/scripts/preload-impressum-page-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload Mitglied werden page',
|
||||
path: 'src/scripts/preload-mitglied-werden-page-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload Netzwerk page',
|
||||
path: 'src/scripts/preload-netzwerk-page-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload participation page',
|
||||
path: 'src/scripts/preload-participation-page-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload Preisträger index page',
|
||||
path: 'src/scripts/preload-preistraeger-index-page-cms.ts',
|
||||
},
|
||||
{
|
||||
label: 'Preload press index page',
|
||||
path: 'src/scripts/preload-press-index-page-cms.ts',
|
||||
},
|
||||
]
|
||||
|
||||
async function initializeSchema() {
|
||||
const payload = await getPayload({ config })
|
||||
|
||||
payload.logger.info(
|
||||
`Initialized Payload schema for ${Object.keys(payload.collections).length} collections and ${
|
||||
Object.keys(payload.globals.config).length
|
||||
} globals.`,
|
||||
)
|
||||
|
||||
await payload.destroy()
|
||||
}
|
||||
|
||||
function runScript(scriptPath: string) {
|
||||
const result = spawnSync('tsx', [scriptPath], {
|
||||
env: process.env,
|
||||
stdio: 'inherit',
|
||||
})
|
||||
|
||||
if (result.error) throw result.error
|
||||
if (result.status !== 0) throw new Error(`${scriptPath} failed with exit code ${result.status ?? 'unknown'}`)
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('Setting up a fresh Payload database...')
|
||||
console.log('1. Initialize Payload tables')
|
||||
await initializeSchema()
|
||||
|
||||
for (const [index, script] of orderedScripts.entries()) {
|
||||
console.log(`${index + 2}. ${script.label}`)
|
||||
runScript(script.path)
|
||||
}
|
||||
|
||||
console.log('Fresh database setup complete.')
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user