Files
spotlightcam/backend/prisma/seed.production.js
Radosław Gierwiało b556abb854 feat(seed): split seed scripts into production and development
- Create seed.production.js with admin user, divisions, and competition types only
- Rename seed.js to seed.development.js with all test data
- Add admin@spotlight.cam account with isAdmin flag and COMFORT tier
- Update test users to use @spotlight.cam domain and SUPPORTER tier
- Remove wsdcId from test users
- Add npm scripts: prisma:seed:dev and prisma:seed:prod
- Add Makefile targets: seed-dev and seed-prod
2025-12-06 12:23:05 +01:00

97 lines
2.8 KiB
JavaScript

const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function main() {
console.log('🌱 Seeding production database...');
// Create admin user
const adminUser = await prisma.user.upsert({
where: { email: 'admin@spotlight.cam' },
update: {},
create: {
username: 'spotlight_admin',
email: 'admin@spotlight.cam',
passwordHash: '$2b$10$yYiA7KDB2fjTykDWIMVvvus8Ra8wKxKeLipAxiZYMnklyT3UnVSWK',
firstName: 'Admin',
lastName: 'User',
emailVerified: true,
isAdmin: true,
accountTier: 'COMFORT',
},
});
console.log(`✅ Created admin user: ${adminUser.username}`);
// 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`);
console.log('🎉 Production seeding completed successfully!');
console.log('');
console.log('Created:');
console.log(` - 1 admin user`);
console.log(` - ${divisions.length} divisions`);
console.log(` - ${competitionTypes.length} competition types`);
console.log('');
console.log('Admin account:');
console.log(' - admin@spotlight.cam / spotlight_admin (COMFORT tier)');
}
main()
.catch((e) => {
console.error('❌ Seeding failed:', e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});