feat(03-03): extend seed.ts with client and placeholder document rows
- Added import of clients, documents, inArray from drizzle-orm - Seeds 2 clients: Sarah Johnson and Mike Torres (onConflictDoNothing) - Queries back seeded client IDs, then seeds 4 placeholder documents - Documents cover Signed/Sent/Draft statuses across both clients - Seed is idempotent via onConflictDoNothing guard
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import "dotenv/config";
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
import { users } from "../src/lib/db/schema";
|
||||
import { users, clients, documents } from "../src/lib/db/schema";
|
||||
import bcrypt from "bcryptjs";
|
||||
import { inArray } from "drizzle-orm";
|
||||
|
||||
const client = postgres(process.env.DATABASE_URL!);
|
||||
const db = drizzle({ client });
|
||||
@@ -20,6 +21,36 @@ async function seed() {
|
||||
await db.insert(users).values({ email, passwordHash }).onConflictDoNothing();
|
||||
|
||||
console.log(`Seeded agent account: ${email}`);
|
||||
|
||||
// Seed clients
|
||||
await db.insert(clients).values([
|
||||
{ name: "Sarah Johnson", email: "sarah.j@example.com" },
|
||||
{ name: "Mike Torres", email: "m.torres@example.com" },
|
||||
]).onConflictDoNothing();
|
||||
|
||||
console.log("Seeded clients: Sarah Johnson, Mike Torres");
|
||||
|
||||
// Query back seeded clients to get their IDs
|
||||
const [sarah, mike] = await db
|
||||
.select({ id: clients.id })
|
||||
.from(clients)
|
||||
.where(inArray(clients.email, ["sarah.j@example.com", "m.torres@example.com"]))
|
||||
.orderBy(clients.createdAt);
|
||||
|
||||
// Seed placeholder documents
|
||||
if (sarah && mike) {
|
||||
await db.insert(documents).values([
|
||||
{ name: "Purchase Agreement - 842 Maple Dr", clientId: sarah.id, status: "Signed", sentAt: new Date("2026-02-15") },
|
||||
{ name: "Seller Disclosure - 842 Maple Dr", clientId: sarah.id, status: "Signed", sentAt: new Date("2026-02-14") },
|
||||
{ name: "Buyer Rep Agreement", clientId: mike.id, status: "Sent", sentAt: new Date("2026-03-10") },
|
||||
{ name: "Purchase Agreement - 1205 Oak Ave", clientId: mike.id, status: "Draft", sentAt: null },
|
||||
]).onConflictDoNothing();
|
||||
|
||||
console.log("Seeded 4 placeholder documents");
|
||||
} else {
|
||||
console.log("Skipping documents seed — clients not found");
|
||||
}
|
||||
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user