Phase 1 - Step 2: PostgreSQL Setup **Infrastructure:** - Add PostgreSQL 15 Alpine container to docker-compose.yml - Configure persistent volume for database data - Update backend Dockerfile with OpenSSL for Prisma compatibility **Database Schema (Prisma):** - 6 tables: users, events, chat_rooms, messages, matches, ratings - Foreign key relationships and cascading deletes - Performance indexes on frequently queried columns - Unique constraints for data integrity **Prisma Setup:** - Prisma Client for database queries - Migration system with initial migration - Seed script with 4 test events and chat rooms - Database connection utility with singleton pattern **API Implementation:** - GET /api/events - List all events (with filtering and sorting) - GET /api/events/:id - Get single event with relations - Database connection test on server startup - Graceful database disconnect on shutdown **Seed Data:** - Warsaw Dance Festival 2025 - Swing Camp Barcelona 2025 - Blues Week Herräng 2025 - Krakow Swing Connection 2025 **Testing:** - Database connection verified ✅ - API endpoints returning data from PostgreSQL ✅ - Migrations applied successfully ✅ All systems operational 🚀
87 lines
2.3 KiB
JavaScript
87 lines
2.3 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('🌱 Seeding database...');
|
|
|
|
// Create events
|
|
const events = await Promise.all([
|
|
prisma.event.create({
|
|
data: {
|
|
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.create({
|
|
data: {
|
|
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.create({
|
|
data: {
|
|
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.create({
|
|
data: {
|
|
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(` - ${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();
|
|
});
|