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

@@ -12,6 +12,7 @@ endif
.PHONY: help dev-cli prod-cli \ .PHONY: help dev-cli prod-cli \
dev-up dev-down dev-up-rebuild \ dev-up dev-down dev-up-rebuild \
prod-up prod-down prod-up-rebuild \ prod-up prod-down prod-up-rebuild \
seed-dev seed-prod \
test test-watch test-coverage test test-watch test-coverage
help: help:
@@ -24,6 +25,8 @@ help:
@echo " make prod-up # docker compose --profile prod up -d" @echo " make prod-up # docker compose --profile prod up -d"
@echo " make prod-up-rebuild # docker compose --profile prod up -d --build" @echo " make prod-up-rebuild # docker compose --profile prod up -d --build"
@echo " make prod-down # docker compose --profile prod down" @echo " make prod-down # docker compose --profile prod down"
@echo " make seed-dev # Seed database with development data"
@echo " make seed-prod # Seed database with production data"
@echo " make test # Run backend tests" @echo " make test # Run backend tests"
@echo " make test-watch # Run backend tests in watch mode" @echo " make test-watch # Run backend tests in watch mode"
@echo " make test-coverage # Run backend tests with coverage report" @echo " make test-coverage # Run backend tests with coverage report"
@@ -57,6 +60,13 @@ prod-up-rebuild:
prod-down: prod-down:
$(COMPOSE) --profile prod down $(COMPOSE) --profile prod down
# Database seeding
seed-dev:
$(COMPOSE) exec backend npm run prisma:seed:dev
seed-prod:
$(COMPOSE) exec $(BACKEND_SVC) npm run prisma:seed:prod
# Tests # Tests
test: test:
$(COMPOSE) exec $(BACKEND_SVC) npm test $(COMPOSE) exec $(BACKEND_SVC) npm test

View File

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

View File

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