![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.quebec/public_html/scripts/ |
import { PrismaClient } from '@prisma/client';
import { hash } from 'bcryptjs';
const prisma = new PrismaClient();
async function safeSeedNewFeatures() {
console.log('š± SAFE seeding - only adding NEW features without touching existing data...');
try {
// First, check what already exists to avoid conflicts
const existingCaseNumbers = await prisma.legalCase.findMany({
where: { caseNumber: { not: null } },
select: { caseNumber: true }
});
const existingEmails = await prisma.user.findMany({
select: { email: true }
});
const usedCaseNumbers = existingCaseNumbers.map(c => c.caseNumber);
const usedEmails = existingEmails.map(u => u.email);
console.log(`š Avoiding conflicts with ${usedCaseNumbers.length} existing case numbers and ${usedEmails.length} existing emails`);
// Create sample lawyers ONLY if they don't exist
const sampleLawyers = [
{
email: 'marie.champion@example.com',
name: 'Marie Champion',
username: 'marie-champion-demo',
role: 'LAWYER',
specialization: 'Human Rights & Civil Liberties',
hourlyRate: 450.0,
proBono: true,
isVerified: true,
xpPoints: 2450,
level: 8
},
{
email: 'david.justice@example.com',
name: 'David Justice',
username: 'david-justice-demo',
role: 'LAWYER',
specialization: 'Criminal Law & Prison Rights',
hourlyRate: 380.0,
proBono: true,
isVerified: true,
xpPoints: 1890,
level: 6
}
];
const createdLawyers = [];
for (const lawyer of sampleLawyers) {
if (!usedEmails.includes(lawyer.email)) {
const newLawyer = await prisma.user.create({
data: {
...lawyer,
password: await hash('demo123', 12),
isProfilePublic: true,
totalCases: 50,
wonCases: 40,
averageRating: 4.7
}
});
createdLawyers.push(newLawyer);
console.log(`ā
Created sample lawyer: ${lawyer.name}`);
} else {
console.log(`āļø Skipped ${lawyer.name} - email already exists`);
}
}
// Create sample PUBLIC cases ONLY with unique case numbers
const sampleCases = [
{
title: 'Environmental Justice Class Action',
caseNumber: 'ENV2024001',
description: 'Class action against industrial pollution affecting indigenous communities.',
legalArea: 'Environmental Law',
urgencyLevel: 'HIGH',
category: 'ENVIRONMENTAL'
},
{
title: 'Digital Privacy Rights Challenge',
caseNumber: 'PRIV2024002',
description: 'Constitutional challenge to government surveillance programs.',
legalArea: 'Privacy & Digital Rights',
urgencyLevel: 'NORMAL',
category: 'CIVIL_RIGHTS'
}
];
// Get existing lawyers to assign as lead lawyers
const existingLawyers = await prisma.user.findMany({
where: { role: 'LAWYER' },
take: 2
});
const createdCases = [];
for (let i = 0; i < sampleCases.length; i++) {
const caseData = sampleCases[i];
if (!usedCaseNumbers.includes(caseData.caseNumber)) {
const leadLawyer = existingLawyers[i % existingLawyers.length];
const newCase = await prisma.legalCase.create({
data: {
...caseData,
publicSummary: `Sample case for testing: ${caseData.description}`,
caseType: 'class_action',
status: 'active',
jurisdiction: 'Federal Court',
court: 'Federal Court of Canada',
priority: 'medium',
isPublic: true,
isAcceptingApplications: true,
estimatedValue: 5000000,
riskLevel: 'MEDIUM',
tags: JSON.stringify(['sample', 'demo', caseData.category.toLowerCase()]),
viewCount: Math.floor(Math.random() * 500) + 100,
supporterCount: Math.floor(Math.random() * 50) + 10,
leadLawyerId: leadLawyer.id,
createdBy: leadLawyer.id,
filingDate: new Date('2024-01-15')
}
});
createdCases.push(newCase);
console.log(`ā
Created sample case: ${caseData.title}`);
} else {
console.log(`āļø Skipped case - number ${caseData.caseNumber} already exists`);
}
}
// Create badges (only if none exist)
const existingBadges = await prisma.badge.count();
if (existingBadges === 0) {
const badges = await Promise.all([
prisma.badge.create({
data: {
name: 'Justice Seeker',
description: 'Submitted your first case for legal help',
icon: 'āļø',
category: 'ACHIEVEMENT',
xpReward: 50,
rarity: 'COMMON',
requirements: JSON.stringify({ action: 'submit_case', count: 1 })
}
}),
prisma.badge.create({
data: {
name: 'Pro Bono Hero',
description: 'Completed 10 pro bono cases',
icon: 'š¦ø',
category: 'PRO_BONO',
xpReward: 500,
rarity: 'RARE',
requirements: JSON.stringify({ action: 'complete_pro_bono', count: 10 })
}
}),
prisma.badge.create({
data: {
name: 'Case Supporter',
description: 'Supported 5 different cases',
icon: 'ā¤ļø',
category: 'ACHIEVEMENT',
xpReward: 100,
rarity: 'COMMON',
requirements: JSON.stringify({ action: 'support_cases', count: 5 })
}
})
]);
console.log(`ā
Created ${badges.length} sample badges`);
} else {
console.log(`āļø Skipped badges - ${existingBadges} already exist`);
}
// Make some existing cases public (only if they aren't already)
const privateCases = await prisma.legalCase.findMany({
where: { isPublic: false },
take: 1
});
if (privateCases.length > 0) {
const caseToMakePublic = privateCases[0];
await prisma.legalCase.update({
where: { id: caseToMakePublic.id },
data: {
isPublic: true,
publicSummary: 'This case is now visible in the public case arena.',
legalArea: 'Human Rights',
category: 'HUMAN_RIGHTS',
urgencyLevel: 'HIGH',
viewCount: 250,
supporterCount: 45,
tags: JSON.stringify(['prison-rights', 'class-action', 'human-rights'])
}
});
console.log(`ā
Made existing case "${caseToMakePublic.title}" public`);
}
console.log('\nš SAFE seeding completed successfully!');
console.log('ā
No existing data was modified');
console.log('ā
Only new sample data was added');
console.log('ā
Your current cases and users are untouched');
} catch (error) {
console.error('ā Error in safe seeding:', error);
throw error;
} finally {
await prisma.$disconnect();
}
}
if (require.main === module) {
safeSeedNewFeatures()
.catch((error) => {
console.error(error);
process.exit(1);
});
}
export { safeSeedNewFeatures };