Spaces:
Build error
Build error
Upload prisma/seed.ts
Browse files- prisma/seed.ts +106 -0
prisma/seed.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Prisma seed script β populates development database
|
| 2 |
+
// Run: npx prisma db seed
|
| 3 |
+
import { PrismaClient } from '@prisma/client'
|
| 4 |
+
|
| 5 |
+
const prisma = new PrismaClient()
|
| 6 |
+
|
| 7 |
+
async function main() {
|
| 8 |
+
console.log('π± Seeding database...')
|
| 9 |
+
|
| 10 |
+
// ββ Categories ββ
|
| 11 |
+
const cats = await Promise.all([
|
| 12 |
+
{ name:'Venues', slug:'venues', emoji:'ποΈ', sortOrder:1 },
|
| 13 |
+
{ name:'Photographers', slug:'photographers', emoji:'πΈ', sortOrder:2 },
|
| 14 |
+
{ name:'Florists', slug:'florists', emoji:'π', sortOrder:3 },
|
| 15 |
+
{ name:'Catering', slug:'catering', emoji:'π½οΈ', sortOrder:4 },
|
| 16 |
+
{ name:'Music & DJ', slug:'music-dj', emoji:'π΅', sortOrder:5 },
|
| 17 |
+
{ name:'Bridal Wear', slug:'bridal-wear', emoji:'π', sortOrder:6 },
|
| 18 |
+
{ name:'Decorators', slug:'decorators', emoji:'β¨', sortOrder:7 },
|
| 19 |
+
{ name:'Makeup & Hair', slug:'makeup-hair', emoji:'π', sortOrder:8 },
|
| 20 |
+
].map(cat => prisma.category.create({ data: cat })))
|
| 21 |
+
|
| 22 |
+
console.log(` β ${cats.length} categories created`)
|
| 23 |
+
|
| 24 |
+
// ββ Demo Users ββ
|
| 25 |
+
const clientUser = await prisma.user.create({
|
| 26 |
+
data: {
|
| 27 |
+
email: 'client@evermore.lk',
|
| 28 |
+
fullName: 'Amaya Perera',
|
| 29 |
+
passwordHash: '$2b$12$placeholder_hash', // bcrypt hash of 'password123'
|
| 30 |
+
roles: { create: { role: 'CLIENT', isPrimary: true } },
|
| 31 |
+
clientProfile: { create: { partnerName:'Ruwan', weddingDate:new Date('2027-01-15'), location:'Colombo', guestCount:180 } },
|
| 32 |
+
},
|
| 33 |
+
})
|
| 34 |
+
|
| 35 |
+
const vendorUser = await prisma.user.create({
|
| 36 |
+
data: {
|
| 37 |
+
email: 'vendor@lensandlight.lk',
|
| 38 |
+
fullName: 'Kaveen Rajapakse',
|
| 39 |
+
passwordHash: '$2b$12$placeholder_hash',
|
| 40 |
+
roles: { create: { role: 'VENDOR', isPrimary: true } },
|
| 41 |
+
vendorProfile: { create: { businessName:'Lens & Light Studio', categoryId:cats[1].id, district:'Colombo 3', description:'Award-winning wedding photography', isVerified:true, isPublished:true } },
|
| 42 |
+
},
|
| 43 |
+
})
|
| 44 |
+
|
| 45 |
+
const adminUser = await prisma.user.create({
|
| 46 |
+
data: {
|
| 47 |
+
email: 'admin@evermore.lk',
|
| 48 |
+
fullName: 'Admin User',
|
| 49 |
+
passwordHash: '$2b$12$placeholder_hash',
|
| 50 |
+
roles: { create: { role: 'ADMIN', isPrimary: true } },
|
| 51 |
+
adminProfile: { create: { permissions: ['MANAGE_VENDORS','MANAGE_CONTRACTS','MANAGE_USERS','SYSTEM_ADMIN'] } },
|
| 52 |
+
},
|
| 53 |
+
})
|
| 54 |
+
|
| 55 |
+
console.log(` β 3 demo users created (client, vendor, admin)`)
|
| 56 |
+
|
| 57 |
+
// ββ Sample Contract ββ
|
| 58 |
+
const contract = await prisma.contract.create({
|
| 59 |
+
data: {
|
| 60 |
+
bookingId: 'placeholder', // Requires a real booking
|
| 61 |
+
vendorId: vendorUser.id,
|
| 62 |
+
clientId: clientUser.id,
|
| 63 |
+
title: 'Full Day Photography',
|
| 64 |
+
serviceType: 'Photography',
|
| 65 |
+
totalAmount: 150000,
|
| 66 |
+
status: 'PENDING',
|
| 67 |
+
version: 1,
|
| 68 |
+
sections: {
|
| 69 |
+
create: [
|
| 70 |
+
{ sortOrder:1, title:'Scope of Services', content:'Full-day wedding photography coverage. Two photographers. Minimum 400 edited images.' },
|
| 71 |
+
{ sortOrder:2, title:'Payment Terms', content:'Total: Rs. 150,000. Deposit: Rs. 50,000. Balance: Rs. 100,000 due 7 days before event.' },
|
| 72 |
+
],
|
| 73 |
+
},
|
| 74 |
+
deliverables: {
|
| 75 |
+
create: [
|
| 76 |
+
{ description:'Edited high-resolution images', dueDate:new Date('2027-02-15'), quantity:400, acceptanceCriteria:'Color-corrected, professionally edited' },
|
| 77 |
+
{ description:'Premium layflat album', dueDate:new Date('2027-03-15'), quantity:1, acceptanceCriteria:'30 pages, leather cover' },
|
| 78 |
+
],
|
| 79 |
+
},
|
| 80 |
+
auditLogs: {
|
| 81 |
+
create: [
|
| 82 |
+
{ action:'created', actorId:vendorUser.id, actorRole:'VENDOR', detail:'Contract created' },
|
| 83 |
+
{ action:'sent', actorId:vendorUser.id, actorRole:'VENDOR', detail:'Sent to client' },
|
| 84 |
+
],
|
| 85 |
+
},
|
| 86 |
+
},
|
| 87 |
+
})
|
| 88 |
+
|
| 89 |
+
// Contract version snapshot
|
| 90 |
+
await prisma.contractVersion.create({
|
| 91 |
+
data: {
|
| 92 |
+
contractId: contract.id,
|
| 93 |
+
version: 1,
|
| 94 |
+
reason: 'Initial creation',
|
| 95 |
+
snapshot: { title:'Full Day Photography', sections:[], deliverables:[], amount:150000 },
|
| 96 |
+
createdBy: vendorUser.id,
|
| 97 |
+
},
|
| 98 |
+
})
|
| 99 |
+
|
| 100 |
+
console.log(` β Sample contract created with audit log + version snapshot`)
|
| 101 |
+
console.log('\nβ
Seed complete!')
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
main()
|
| 105 |
+
.catch(e => { console.error(e); process.exit(1) })
|
| 106 |
+
.finally(() => prisma.$disconnect())
|