Files
spotlightcam/backend/prisma/seed.js
Radosław Gierwiało 02d3d7ac42 feat: add competition heats system backend
- Add 3 new database tables: divisions, competition_types, event_user_heats
- Add seed data for 6 divisions (NEW, NOV, INT, ADV, ALL, CHA) and 2 competition types (J&J, STR)
- Add API endpoints for divisions and competition types
- Add heats management endpoints in events route (POST/GET/DELETE)
- Implement unique constraint: cannot have same role in same division+competition type
- Add participant verification before allowing heats management
- Support heat numbers 1-9 with optional Leader/Follower role
2025-11-14 15:32:40 +01:00

153 lines
4.5 KiB
JavaScript

const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function main() {
console.log('🌱 Seeding database...');
// Create divisions
const divisions = await Promise.all([
prisma.division.upsert({
where: { name: 'Newcomer' },
update: {},
create: { name: 'Newcomer', abbreviation: 'NEW', displayOrder: 1 },
}),
prisma.division.upsert({
where: { name: 'Novice' },
update: {},
create: { name: 'Novice', abbreviation: 'NOV', displayOrder: 2 },
}),
prisma.division.upsert({
where: { name: 'Intermediate' },
update: {},
create: { name: 'Intermediate', abbreviation: 'INT', displayOrder: 3 },
}),
prisma.division.upsert({
where: { name: 'Advanced' },
update: {},
create: { name: 'Advanced', abbreviation: 'ADV', displayOrder: 4 },
}),
prisma.division.upsert({
where: { name: 'All-Star' },
update: {},
create: { name: 'All-Star', abbreviation: 'ALL', displayOrder: 5 },
}),
prisma.division.upsert({
where: { name: 'Champion' },
update: {},
create: { name: 'Champion', abbreviation: 'CHA', displayOrder: 6 },
}),
]);
console.log(`✅ Created ${divisions.length} divisions`);
// Create competition types
const competitionTypes = await Promise.all([
prisma.competitionType.upsert({
where: { name: 'Jack & Jill' },
update: {},
create: { name: 'Jack & Jill', abbreviation: 'J&J' },
}),
prisma.competitionType.upsert({
where: { name: 'Strictly' },
update: {},
create: { name: 'Strictly', abbreviation: 'STR' },
}),
]);
console.log(`✅ Created ${competitionTypes.length} competition types`);
// Create events
const events = await Promise.all([
prisma.event.upsert({
where: { slug: 'warsaw-dance-festival-2025' },
update: {},
create: {
slug: 'warsaw-dance-festival-2025',
name: 'Warsaw Dance Festival 2025',
location: 'Warsaw, Poland',
startDate: new Date('2025-03-15'),
endDate: new Date('2025-03-17'),
worldsdcId: 'wdf-2025',
participantsCount: 156,
description: 'The biggest West Coast Swing event in Central Europe',
},
}),
prisma.event.upsert({
where: { slug: 'swing-camp-barcelona-2025' },
update: {},
create: {
slug: 'swing-camp-barcelona-2025',
name: 'Swing Camp Barcelona 2025',
location: 'Barcelona, Spain',
startDate: new Date('2025-04-20'),
endDate: new Date('2025-04-23'),
worldsdcId: 'scb-2025',
participantsCount: 203,
description: 'International swing dance camp with workshops and socials',
},
}),
prisma.event.upsert({
where: { slug: 'blues-week-herrang-2025' },
update: {},
create: {
slug: 'blues-week-herrang-2025',
name: 'Blues Week Herräng 2025',
location: 'Herräng, Sweden',
startDate: new Date('2025-07-14'),
endDate: new Date('2025-07-20'),
worldsdcId: 'bwh-2025',
participantsCount: 89,
description: 'Week-long blues dance intensive in the heart of Sweden',
},
}),
prisma.event.upsert({
where: { slug: 'krakow-swing-connection-2025' },
update: {},
create: {
slug: 'krakow-swing-connection-2025',
name: 'Krakow Swing Connection 2025',
location: 'Krakow, Poland',
startDate: new Date('2025-05-10'),
endDate: new Date('2025-05-12'),
worldsdcId: 'ksc-2025',
participantsCount: 127,
description: 'Three days of swing dancing in historic Krakow',
},
}),
]);
console.log(`✅ Created ${events.length} events`);
// Create event chat rooms for each event
const chatRooms = await Promise.all(
events.map((event) =>
prisma.chatRoom.create({
data: {
eventId: event.id,
type: 'event',
},
})
)
);
console.log(`✅ Created ${chatRooms.length} event chat rooms`);
console.log('🎉 Seeding completed successfully!');
console.log('');
console.log('Created:');
console.log(` - ${divisions.length} divisions`);
console.log(` - ${competitionTypes.length} competition types`);
console.log(` - ${events.length} events`);
console.log(` - ${chatRooms.length} chat rooms`);
}
main()
.catch((e) => {
console.error('❌ Seeding failed:', e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});