Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 62 additions & 25 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@ import { prisma } from "@/utils/db/prisma"
* Database seed script for initial data population.
* Run with: npm run db:seed
*/

async function main() {
console.log("🌱 Starting database seeding...")

try {
// ============================================
// Seed app schema models
// ============================================
console.log("📦 Seeding app schema...")
try{

// seed and return results for counter types
const counter = await prisma.counter.create({
data: {name: "Counter"}
})
const reception = await prisma.counter.create({
data: {name: "Reception"}
})
const quickTransaction = await prisma.counter.create({
data: {name: "Quick Transaction"}
})
const training = await prisma.counter.create({
data: {name: "Training"}
})

const locations = [
{
// create location "test Office" with connection to all counters
await prisma.location.create({
data: {
legacyOfficeNumber: 999,
name: "Test Office",
timezone: "America/Dawson_Creek",
Expand All @@ -24,8 +34,26 @@ async function main() {
phoneNumber: "250-555-0100",
latitude: 48.458359,
longitude: -123.377106,
},
{
locationCounters: { create: [
{
counterId: counter.id
},
{
counterId: reception.id
},
{
counterId: quickTransaction.id
},
{
counterId: training.id
}
]}
}
})

// create location "Victoria" with connection to reception and counter counter type
await prisma.location.create({
data: {
legacyOfficeNumber: 94,
name: "Victoria",
timezone: "America/Vancouver",
Expand All @@ -34,31 +62,40 @@ async function main() {
phoneNumber: "250-555-0200",
latitude: 48.458359,
longitude: -123.377106,
},
{
locationCounters: {
createMany: {
data: [
{counterId: counter.id},
{counterId: reception.id},
]
}
}
}
})

// create location "Nanaimo" with no connections to counters
await prisma.location.create({
data: {
legacyOfficeNumber: 701,
name: "Citz_IMB_Victoria",
name: "Nanaimo",
timezone: "America/Vancouver",
streetAddress: "4000 Seymour Place, Victoria BC V8X 5J2",
streetAddress: "460 Selby St, Nanaimo, BC V9R 2R7",
mailAddress: "PO Box 9000, Victoria, BC V8W 9A1",
phoneNumber: "250-555-0300",
latitude: 48.458359,
longitude: -123.377106,
},
]

await prisma.location.createMany({
data: locations,
skipDuplicates: true,
}
})
console.log(`✅ Seeded ${locations.length} locations`)

console.log("✅ Database seeding completed successfully!")
} catch (error) {
console.error("❌ Seeding failed:", error)

console.error("❌ Seeding database failed:", error)
process.exit(1)

} finally {
await prisma.$disconnect()

console.log("✅ Database seeding completed successfully!")
await prisma.$disconnect()

}
}

Expand Down