diff --git a/packages/db/src/seed/demo/index.ts b/packages/db/src/seed/demo/index.ts index 20f041b..8e96e95 100644 --- a/packages/db/src/seed/demo/index.ts +++ b/packages/db/src/seed/demo/index.ts @@ -46,8 +46,9 @@ * always run in; sections depend on ids the earlier ones return. */ import { quarterBoundsFor } from '@pig/core'; +import { sql } from 'drizzle-orm'; import { createDatabase, type Database } from '../../client'; -import { users } from '../../schema/index'; +import { capacityCommitments, demandDeals, supplyDeals, users } from '../../schema/index'; import { seedSupplyActivities } from './activities'; import { seedFacts } from './agent'; import { seedCalendar } from './calendar'; @@ -175,14 +176,32 @@ export async function seedDemo(context: DemoContext): Promise { const facts = await seedFacts(context); - console.log(' 5 capacity commitments (4 live, 1 lapsed), with sites, MSAs and negotiated SLAs'); + /* + * Counted, not asserted. These lines were hardcoded when the book was split + * into modules, and they drifted the moment the seed grew: the summary + * claimed 12 demand deals and 5 commitments against a database holding 13 + * and 6. A seed that misreports what it wrote teaches an operator to + * distrust the only feedback the command gives them. + */ + const [written] = await context.db + .select({ + commitments: sql`(select count(*)::int from ${capacityCommitments})`, + demandDeals: sql`(select count(*)::int from ${demandDeals})`, + supplyDeals: sql`(select count(*)::int from ${supplyDeals})`, + demandStages: sql`(select count(distinct stage)::int from ${demandDeals})`, + }) + .from(sql`(select 1) as one`); + const book = written ?? { commitments: 0, demandDeals: 0, supplyDeals: 0, demandStages: 0 }; + + console.log(` ${book.commitments} capacity commitments, with sites, MSAs and negotiated SLAs`); console.log(` ${facts.total} agent-derived facts (${facts.added} new) — 2 applied, 4 awaiting review`); console.log( ` ${facts.tasks} agent tasks and ${facts.runs} Piggy runs, ${facts.actions} idempotency-keyed actions, ` + `${(facts.costMicroCents / 1_000_000).toFixed(4)} cents of model spend`, ); console.log( - ' 12 demand deals across all ten stages — 2 won, 1 lost, 1 expansion off a closed parent — and 8 supply deals', + ` ${book.demandDeals} demand deals across ${book.demandStages} stages — including a won parent with its ` + + `expansion child, and a loss with a reason — and ${book.supplyDeals} supply deals`, ); console.log(' Allocations including one unconverted hold and internal research burn'); console.log(