From b556abb854d28169ae55fda1b977a80eec731dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Gierwia=C5=82o?= Date: Sat, 6 Dec 2025 12:23:05 +0100 Subject: [PATCH] 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 --- Makefile | 10 ++ backend/package.json | 6 +- .../prisma/{seed.js => seed.development.js} | 40 ++++++-- backend/prisma/seed.production.js | 96 +++++++++++++++++++ 4 files changed, 141 insertions(+), 11 deletions(-) rename backend/prisma/{seed.js => seed.development.js} (90%) create mode 100644 backend/prisma/seed.production.js diff --git a/Makefile b/Makefile index 10113ea..ddef7be 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ endif .PHONY: help dev-cli prod-cli \ dev-up dev-down dev-up-rebuild \ prod-up prod-down prod-up-rebuild \ + seed-dev seed-prod \ test test-watch test-coverage help: @@ -24,6 +25,8 @@ help: @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-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-watch # Run backend tests in watch mode" @echo " make test-coverage # Run backend tests with coverage report" @@ -57,6 +60,13 @@ prod-up-rebuild: 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 test: $(COMPOSE) exec $(BACKEND_SVC) npm test diff --git a/backend/package.json b/backend/package.json index 4d56b34..7e1f61b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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": { diff --git a/backend/prisma/seed.js b/backend/prisma/seed.development.js similarity index 90% rename from backend/prisma/seed.js rename to backend/prisma/seed.development.js index d288250..144ebb4 100644 --- a/backend/prisma/seed.js +++ b/backend/prisma/seed.development.js @@ -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!'); diff --git a/backend/prisma/seed.production.js b/backend/prisma/seed.production.js new file mode 100644 index 0000000..036e7b6 --- /dev/null +++ b/backend/prisma/seed.production.js @@ -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(); + });