116 lines
3.6 KiB
TypeScript
116 lines
3.6 KiB
TypeScript
import { PrismaClient, Size } from '@prisma/client'
|
|
import fs from 'fs'
|
|
import path from 'path'
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
async function migrateStaticContent() {
|
|
console.log('Starting migration of static content to database...')
|
|
|
|
// Read projects from projects.json
|
|
const projectsJsonPath = path.join(
|
|
process.cwd(),
|
|
'public',
|
|
'projects',
|
|
'projects.json'
|
|
)
|
|
const projectsData = JSON.parse(fs.readFileSync(projectsJsonPath, 'utf-8'))
|
|
|
|
// Migrate projects
|
|
console.log('Migrating projects...')
|
|
for (const projectData of projectsData) {
|
|
try {
|
|
// Read credits and info files
|
|
const creditsPath = path.join(
|
|
process.cwd(),
|
|
'public',
|
|
projectData.credits
|
|
)
|
|
const infoPath = path.join(process.cwd(), 'public', projectData.info)
|
|
|
|
const credits = fs.existsSync(creditsPath)
|
|
? fs.readFileSync(creditsPath, 'utf-8')
|
|
: ''
|
|
const info = fs.existsSync(infoPath)
|
|
? fs.readFileSync(infoPath, 'utf-8')
|
|
: ''
|
|
|
|
// Check if project already exists
|
|
const existingProject = await prisma.project.findUnique({
|
|
where: { id: projectData.id },
|
|
})
|
|
|
|
if (existingProject) {
|
|
console.log(`Project ${projectData.id} already exists, updating...`)
|
|
await prisma.project.update({
|
|
where: { id: projectData.id },
|
|
data: {
|
|
title: projectData.title,
|
|
description: projectData.description || null,
|
|
thumbnail: `/${projectData.thumbnail}`,
|
|
size: projectData.size === 'big' ? Size.BIG : Size.SMALL,
|
|
embed: projectData.embed || null,
|
|
video: projectData.video || null,
|
|
credits,
|
|
info,
|
|
category: projectData.category || null,
|
|
tags: projectData.tags || null,
|
|
featured: projectData.featured || false,
|
|
published:
|
|
projectData.published !== undefined
|
|
? projectData.published
|
|
: true,
|
|
},
|
|
})
|
|
} else {
|
|
console.log(`Creating project ${projectData.id}...`)
|
|
await prisma.project.create({
|
|
data: {
|
|
id: projectData.id,
|
|
title: projectData.title,
|
|
description: projectData.description || null,
|
|
thumbnail: `/${projectData.thumbnail}`,
|
|
size: projectData.size === 'big' ? Size.BIG : Size.SMALL,
|
|
embed: projectData.embed || null,
|
|
video: projectData.video || null,
|
|
credits,
|
|
info,
|
|
category: projectData.category || null,
|
|
tags: projectData.tags || null,
|
|
featured: projectData.featured || false,
|
|
published:
|
|
projectData.published !== undefined
|
|
? projectData.published
|
|
: true,
|
|
},
|
|
})
|
|
}
|
|
} catch (error) {
|
|
console.error(`Error migrating project ${projectData.id}:`, error)
|
|
}
|
|
}
|
|
|
|
console.log('Projects migration completed.')
|
|
|
|
// Migrate team members (they should already be in the database from seed)
|
|
console.log('Checking team members...')
|
|
const teamMembers = await prisma.teamMember.findMany()
|
|
console.log(`Found ${teamMembers.length} team members in database.`)
|
|
|
|
// Migrate FAQs (they should already be in the database from seed)
|
|
console.log('Checking FAQs...')
|
|
const faqs = await prisma.fAQ.findMany()
|
|
console.log(`Found ${faqs.length} FAQs in database.`)
|
|
|
|
console.log('Migration completed successfully!')
|
|
}
|
|
|
|
migrateStaticContent()
|
|
.catch((e) => {
|
|
console.error(e)
|
|
process.exit(1)
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect()
|
|
})
|