Drizzle ORM patterns -- schema definition, indexes, relations, migrations, transactions, upserts, prepared statements, and connection setup
96
96%
Does it follow best practices?
Impact
98%
1.60xAverage score across 5 eval scenarios
Passed
No known issues
{
"context": "Tests whether the agent uses transactions for multi-table writes, uses tx (not db) inside transactions, destructures .returning() correctly, uses batch .values([]) for bulk inserts, updates updatedAt with SQL expressions, uses InferSelectModel/InferInsertModel for type safety, stores money as integer cents, and defines proper schema with indexes and relations. The task describes billing operations without naming any of these patterns.",
"type": "weighted_checklist",
"checklist": [
{
"name": "Transaction for billing cycle",
"description": "The invoice creation for a billing cycle is wrapped in db.transaction() to ensure all invoices are created atomically",
"max_score": 12
},
{
"name": "Transaction for cancel+invoice",
"description": "The cancel subscription operation wraps both the status update and prorated invoice creation in a single db.transaction() call",
"max_score": 10
},
{
"name": "Uses tx not db inside transaction",
"description": "Inside all transaction callbacks, database operations use the tx parameter, NOT the outer db object",
"max_score": 10
},
{
"name": "Returning destructured as array",
"description": "Results of .returning() are destructured as const [row] = await tx.insert(...).returning(), not accessed via index",
"max_score": 8
},
{
"name": "Batch insert for invoices",
"description": "Multiple invoices in a billing cycle are inserted with a single .values([...]) array call, not individual inserts in a loop",
"max_score": 8
},
{
"name": "updatedAt SQL expression on updates",
"description": "When updating records (payment processing, subscription cancellation), updatedAt is set using sql`datetime('now')` -- not a JavaScript Date object or ISO string",
"max_score": 10
},
{
"name": "InferSelectModel or InferInsertModel used",
"description": "Function signatures use InferSelectModel<typeof table> or InferInsertModel<typeof table> from 'drizzle-orm' for type extraction, not manually duplicated interfaces",
"max_score": 8
},
{
"name": "Money as integer cents",
"description": "Plan prices, invoice amounts, and all monetary values are stored and handled as integer cents",
"max_score": 8
},
{
"name": "Indexes on FK columns",
"description": "Foreign key columns (customerId on subscriptions, customerId and planId on invoices) have explicit indexes",
"max_score": 8
},
{
"name": "References with onDelete",
"description": "Foreign key references include explicit onDelete actions",
"max_score": 5
},
{
"name": "Enum for status fields",
"description": "Subscription status and invoice status use text('col', { enum: [...] }) pattern",
"max_score": 5
},
{
"name": "Operator helpers for conditions",
"description": "WHERE conditions use eq(), and(), etc. from 'drizzle-orm' -- not raw SQL strings",
"max_score": 8
}
]
}