feat: add PostgreSQL database adapter support
This commit is contained in:
Executable
+113
@@ -0,0 +1,113 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Database seed script for EuchreCamp
|
||||
* Creates sample data for testing and development
|
||||
*/
|
||||
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log('🌱 Seeding database...\n');
|
||||
|
||||
// Create admin user if it doesn't exist
|
||||
const adminEmail = 'david@dhg.lol';
|
||||
const existingAdmin = await prisma.user.findUnique({
|
||||
where: { email: adminEmail },
|
||||
});
|
||||
|
||||
if (!existingAdmin) {
|
||||
console.log('Creating admin user...');
|
||||
const passwordHash = await bcrypt.hash('adminadmin', 12);
|
||||
|
||||
const adminUser = await prisma.user.create({
|
||||
data: {
|
||||
email: adminEmail,
|
||||
emailVerified: true,
|
||||
name: 'David Admin',
|
||||
role: 'club_admin',
|
||||
accounts: {
|
||||
create: {
|
||||
id: `admin_${Date.now()}`,
|
||||
accountId: `admin_${Date.now()}`,
|
||||
providerId: 'credential',
|
||||
password: passwordHash,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`✅ Created admin user: ${adminUser.email}`);
|
||||
} else {
|
||||
console.log('✅ Admin user already exists');
|
||||
}
|
||||
|
||||
// Create sample players if none exist
|
||||
const playerCount = await prisma.player.count();
|
||||
if (playerCount === 0) {
|
||||
console.log('\nCreating sample players...');
|
||||
const samplePlayers = [
|
||||
'John Smith',
|
||||
'Jane Doe',
|
||||
'Mike Johnson',
|
||||
'Sarah Brown',
|
||||
'Charlie Wilson',
|
||||
'Diana Davis',
|
||||
'Robert Taylor',
|
||||
'Emily Anderson',
|
||||
'David Martinez',
|
||||
'Lisa Thompson',
|
||||
];
|
||||
|
||||
for (const name of samplePlayers) {
|
||||
await prisma.player.create({
|
||||
data: {
|
||||
name,
|
||||
currentElo: 1000 + Math.floor(Math.random() * 200) - 100,
|
||||
gamesPlayed: Math.floor(Math.random() * 50),
|
||||
wins: Math.floor(Math.random() * 30),
|
||||
losses: Math.floor(Math.random() * 30),
|
||||
},
|
||||
});
|
||||
}
|
||||
console.log(`✅ Created ${samplePlayers.length} sample players`);
|
||||
} else {
|
||||
console.log(`✅ ${playerCount} players already exist`);
|
||||
}
|
||||
|
||||
// Create sample tournament
|
||||
const tournamentCount = await prisma.event.count({
|
||||
where: { eventType: 'tournament' },
|
||||
});
|
||||
|
||||
if (tournamentCount === 0) {
|
||||
console.log('\nCreating sample tournament...');
|
||||
const tournament = await prisma.event.create({
|
||||
data: {
|
||||
name: 'Sample Tournament',
|
||||
eventType: 'tournament',
|
||||
format: 'round_robin',
|
||||
eventDate: new Date(),
|
||||
status: 'planned',
|
||||
ownerId: existingAdmin?.id,
|
||||
},
|
||||
});
|
||||
console.log(`✅ Created sample tournament: ${tournament.name}`);
|
||||
} else {
|
||||
console.log('✅ Tournaments already exist');
|
||||
}
|
||||
|
||||
console.log('\n🌱 Seeding completed successfully!');
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error('❌ Seeding failed:', e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user