From d21b8d6a277c03a9da36a9b82de03fad1205c12f Mon Sep 17 00:00:00 2001 From: Taylor Friesen Date: Mon, 9 Feb 2026 13:55:18 -0800 Subject: [PATCH 1/3] add base counter type seed data --- prisma/seed.ts | 60 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index 01e5bd97..0d23d76d 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,18 +1,40 @@ import { prisma } from "@/utils/db/prisma" + /** - * Database seed script for initial data population. - * Run with: npm run db:seed + * Seed information to populate the counter table with initial data. */ +async function seedCounters() { + try { + console.log("📦 Seeding app counters...") -async function main() { - console.log("🌱 Starting database seeding...") + const counters = [ + {name: "Reception"}, + {name: "Quick Transaction"}, + {name: "Counter"}, + {name: "Ptax"}, + {name: "Cheque P/U"}, + {name: "ICBC Test"}, + {name: "Training"}, + ] + + await prisma.counter.createMany({ + data: counters, + skipDuplicates: true, + }) + console.log(`✅ Seeded ${counters.length} counters`) + + } catch (error) { + console.error("❌ Seeding counters failed:", error) +} +} +/** + * Seed information to populate the location table with initial data. + */ +async function seedLocations() { try { - // ============================================ - // Seed app schema models - // ============================================ - console.log("📦 Seeding app schema...") + console.log("📦 Seeding app locations...") const locations = [ { @@ -53,13 +75,23 @@ async function main() { }) console.log(`✅ Seeded ${locations.length} locations`) - console.log("✅ Database seeding completed successfully!") } catch (error) { - console.error("❌ Seeding failed:", error) - process.exit(1) - } finally { - await prisma.$disconnect() - } + console.error("❌ Seeding locations failed:", error) +}} + +/** + * Database seed script for initial data population. + * Run with: npm run db:seed + */ +async function main() { + console.log("🌱 Starting database seeding...") + + await seedLocations() + await seedCounters() + + console.log("✅ Database seeding completed successfully!") + await prisma.$disconnect() + } main() From 9108485cce2e5bf0ead9525185145288cfab75e4 Mon Sep 17 00:00:00 2001 From: Taylor Friesen Date: Tue, 10 Feb 2026 08:27:33 -0800 Subject: [PATCH 2/3] update seed file to work with relation table --- prisma/seed.ts | 116 +++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 56 deletions(-) diff --git a/prisma/seed.ts b/prisma/seed.ts index 0d23d76d..b2128907 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -1,43 +1,31 @@ import { prisma } from "@/utils/db/prisma" - /** - * Seed information to populate the counter table with initial data. + * Database seed script for initial data population. + * Run with: npm run db:seed */ -async function seedCounters() { - try { - console.log("📦 Seeding app counters...") +async function main() { + console.log("🌱 Starting database seeding...") - const counters = [ - {name: "Reception"}, - {name: "Quick Transaction"}, - {name: "Counter"}, - {name: "Ptax"}, - {name: "Cheque P/U"}, - {name: "ICBC Test"}, - {name: "Training"}, - ] + try{ - await prisma.counter.createMany({ - data: counters, - skipDuplicates: true, + // 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"} }) - console.log(`✅ Seeded ${counters.length} counters`) - - } catch (error) { - console.error("❌ Seeding counters failed:", error) -} -} - -/** - * Seed information to populate the location table with initial data. - */ -async function seedLocations() { - try { - console.log("📦 Seeding app locations...") - 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", @@ -46,8 +34,26 @@ async function seedLocations() { 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", @@ -56,42 +62,40 @@ async function seedLocations() { 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`) - } catch (error) { - console.error("❌ Seeding locations failed:", error) -}} -/** - * Database seed script for initial data population. - * Run with: npm run db:seed - */ -async function main() { - console.log("🌱 Starting database seeding...") + console.error("❌ Seeding database failed:", error) - await seedLocations() - await seedCounters() + } finally { console.log("✅ Database seeding completed successfully!") await prisma.$disconnect() + } } main() From b2ed37e3fe25c479399a35697c1304c15faeca61 Mon Sep 17 00:00:00 2001 From: Taylor Friesen Date: Tue, 10 Feb 2026 08:54:48 -0800 Subject: [PATCH 3/3] add back exit on error --- prisma/seed.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/prisma/seed.ts b/prisma/seed.ts index b2128907..d41cc245 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -89,6 +89,7 @@ async function main() { } catch (error) { console.error("❌ Seeding database failed:", error) + process.exit(1) } finally {