feat(server): add Program and Award database models
- Add Program and Award tables to Prisma schema - Update program-config.service to support database with JSON fallback - Update ProgramCard.vue display logic for dynamic teamName/performer - Add seed script to import data from JSON config Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,6 @@ datasource db {
|
||||
model User {
|
||||
id String @id @default(cuid())
|
||||
name String @db.VarChar(100)
|
||||
department String @db.VarChar(100)
|
||||
avatar String? @db.VarChar(512)
|
||||
birthYear Int? @map("birth_year")
|
||||
zodiac String? @db.VarChar(20)
|
||||
@@ -93,6 +92,37 @@ model DrawResult {
|
||||
@@map("draw_results")
|
||||
}
|
||||
|
||||
// Programs for voting
|
||||
model Program {
|
||||
id String @id @default(cuid())
|
||||
name String @db.VarChar(100)
|
||||
teamName String @default("") @map("team_name") @db.VarChar(100)
|
||||
performer String @default("") @db.VarChar(200)
|
||||
order Int @default(0)
|
||||
remark String? @db.Text
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@index([order])
|
||||
@@map("programs")
|
||||
}
|
||||
|
||||
// Awards for voting
|
||||
model Award {
|
||||
id String @id @default(cuid())
|
||||
name String @db.VarChar(100)
|
||||
icon String @db.VarChar(20)
|
||||
order Int @default(0)
|
||||
remark String? @db.Text
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
@@index([order])
|
||||
@@map("awards")
|
||||
}
|
||||
|
||||
// Draw sessions
|
||||
model DrawSession {
|
||||
id String @id @default(cuid())
|
||||
|
||||
110
packages/server/prisma/seed.ts
Normal file
110
packages/server/prisma/seed.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Prisma Seed Script
|
||||
* Populates initial program and award data from JSON config
|
||||
*/
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
interface ProgramData {
|
||||
id: string;
|
||||
name: string;
|
||||
teamName: string;
|
||||
performer: string;
|
||||
order: number;
|
||||
remark: string;
|
||||
}
|
||||
|
||||
interface AwardData {
|
||||
id: string;
|
||||
name: string;
|
||||
icon: string;
|
||||
order: number;
|
||||
remark: string;
|
||||
}
|
||||
|
||||
interface ConfigFile {
|
||||
programs: ProgramData[];
|
||||
awards: AwardData[];
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('Starting seed...');
|
||||
|
||||
// Load config from JSON file
|
||||
const configPath = path.join(__dirname, '../config/programs.json');
|
||||
|
||||
if (!fs.existsSync(configPath)) {
|
||||
console.error('Config file not found:', configPath);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const config: ConfigFile = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
|
||||
|
||||
// Seed programs
|
||||
console.log(`Seeding ${config.programs.length} programs...`);
|
||||
for (const p of config.programs) {
|
||||
await prisma.program.upsert({
|
||||
where: { id: p.id },
|
||||
create: {
|
||||
id: p.id,
|
||||
name: p.name,
|
||||
teamName: p.teamName || '',
|
||||
performer: p.performer || '',
|
||||
order: p.order,
|
||||
remark: p.remark || null,
|
||||
isActive: true,
|
||||
},
|
||||
update: {
|
||||
name: p.name,
|
||||
teamName: p.teamName || '',
|
||||
performer: p.performer || '',
|
||||
order: p.order,
|
||||
remark: p.remark || null,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
console.log(` - ${p.name}`);
|
||||
}
|
||||
|
||||
// Seed awards
|
||||
console.log(`Seeding ${config.awards.length} awards...`);
|
||||
for (const a of config.awards) {
|
||||
await prisma.award.upsert({
|
||||
where: { id: a.id },
|
||||
create: {
|
||||
id: a.id,
|
||||
name: a.name,
|
||||
icon: a.icon,
|
||||
order: a.order,
|
||||
remark: a.remark || null,
|
||||
isActive: true,
|
||||
},
|
||||
update: {
|
||||
name: a.name,
|
||||
icon: a.icon,
|
||||
order: a.order,
|
||||
remark: a.remark || null,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
console.log(` - ${a.name}`);
|
||||
}
|
||||
|
||||
console.log('Seed completed!');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error('Seed failed:', e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user