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
This commit is contained in:
Radosław Gierwiało
2025-12-06 12:23:05 +01:00
parent 4066bf1081
commit b556abb854
4 changed files with 141 additions and 11 deletions

View File

@@ -10,7 +10,9 @@
"test:watch": "jest --watch",
"prisma:generate": "prisma generate",
"prisma:migrate": "prisma migrate dev",
"prisma:seed": "node prisma/seed.js",
"prisma:seed": "node prisma/seed.development.js",
"prisma:seed:dev": "node prisma/seed.development.js",
"prisma:seed:prod": "node prisma/seed.production.js",
"prisma:studio": "prisma studio",
"cli": "node src/cli/index.js"
},
@@ -65,7 +67,7 @@
}
},
"prisma": {
"seed": "node prisma/seed.js"
"seed": "node prisma/seed.development.js"
},
"overrides": {
"csurf": {

View File

@@ -6,19 +6,37 @@ const prisma = new PrismaClient();
async function main() {
console.log('🌱 Seeding 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 test users
const testUsers = await Promise.all([
prisma.user.upsert({
where: { email: 'john@example.com' },
where: { email: 'john@spotlight.cam' },
update: {},
create: {
username: 'john_dancer',
email: 'john@example.com',
email: 'john@spotlight.cam',
passwordHash: await bcrypt.hash('Dance123!', 10),
firstName: 'John',
lastName: 'Smith',
wsdcId: '12345',
emailVerified: true,
accountTier: 'SUPPORTER',
country: 'United States',
city: 'Los Angeles',
instagramUrl: 'https://instagram.com/johndancer',
@@ -26,16 +44,16 @@ async function main() {
},
}),
prisma.user.upsert({
where: { email: 'sarah@example.com' },
where: { email: 'sarah@spotlight.cam' },
update: {},
create: {
username: 'sarah_swings',
email: 'sarah@example.com',
email: 'sarah@spotlight.cam',
passwordHash: await bcrypt.hash('Swing456!', 10),
firstName: 'Sarah',
lastName: 'Johnson',
wsdcId: '23456',
emailVerified: true,
accountTier: 'SUPPORTER',
country: 'United Kingdom',
city: 'London',
tiktokUrl: 'https://tiktok.com/@sarahswings',
@@ -43,16 +61,16 @@ async function main() {
},
}),
prisma.user.upsert({
where: { email: 'mike@example.com' },
where: { email: 'mike@spotlight.cam' },
update: {},
create: {
username: 'mike_blues',
email: 'mike@example.com',
email: 'mike@spotlight.cam',
passwordHash: await bcrypt.hash('Blues789!', 10),
firstName: 'Mike',
lastName: 'Williams',
wsdcId: '34567',
emailVerified: true,
accountTier: 'SUPPORTER',
country: 'Sweden',
city: 'Stockholm',
instagramUrl: 'https://instagram.com/mikeblues',
@@ -332,6 +350,7 @@ async function main() {
console.log('🎉 Seeding completed successfully!');
console.log('');
console.log('Created:');
console.log(` - 1 admin user`);
console.log(` - ${testUsers.length} test users`);
console.log(` - ${divisions.length} divisions`);
console.log(` - ${competitionTypes.length} competition types`);
@@ -340,6 +359,9 @@ async function main() {
console.log(` - ${eventParticipants.length} event participants`);
console.log(` - ${heats.length} sample heats`);
console.log('');
console.log('Admin account:');
console.log(' - admin@spotlight.cam / spotlight_admin (COMFORT tier)');
console.log('');
console.log('Test accounts:');
console.log(' 1. john_dancer / Dance123!');
console.log(' 2. sarah_swings / Swing456!');

View File

@@ -0,0 +1,96 @@
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();
});