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 onConflictDoUpdate for atomic upserts instead of check-then-insert, wraps the sync in a transaction, uses batch operations, updates updatedAt with SQL expressions, and uses the tx parameter inside transactions. The task describes a sync requirement without naming any of these patterns.",
"type": "weighted_checklist",
"checklist": [
{
"name": "Upsert with onConflictDoUpdate",
"description": "Product upsert uses db.insert(products).values(...).onConflictDoUpdate({ target: products.sku, set: { ... } }) for atomic insert-or-update -- NOT a check-then-insert pattern (select then conditionally insert or update)",
"max_score": 18
},
{
"name": "No check-then-insert pattern",
"description": "The code does NOT query for existing records before deciding to insert or update -- uses onConflictDoUpdate or onConflictDoNothing instead",
"max_score": 10
},
{
"name": "Transaction wraps the entire sync",
"description": "The product upserts AND the sync log insert are wrapped in a single db.transaction() call so a partial failure rolls back everything",
"max_score": 12
},
{
"name": "Uses tx inside transaction",
"description": "Inside the transaction callback, all database operations use the tx parameter, not the outer db object",
"max_score": 10
},
{
"name": "updatedAt uses SQL expression",
"description": "The upsert's set clause updates updatedAt using sql`datetime('now')` or sql`(datetime('now'))` -- not a JavaScript Date object or ISO string",
"max_score": 10
},
{
"name": "Batch processing for efficiency",
"description": "Products are not inserted one at a time in a loop with individual await calls -- uses batch .values([]) array inserts, or processes in chunks to reduce round trips",
"max_score": 8
},
{
"name": "excluded reference in set clause",
"description": "The onConflictDoUpdate set clause references the incoming values using sql`excluded.column_name` or the equivalent Drizzle pattern",
"max_score": 7
},
{
"name": "Money stored as integer cents",
"description": "wholesalePriceCents is handled as integer cents throughout -- no conversion to/from float or decimal",
"max_score": 7
},
{
"name": "Return value from transaction",
"description": "The transaction callback returns a result (e.g., sync count or log entry) so the caller receives meaningful feedback",
"max_score": 5
},
{
"name": "Type inference or explicit types",
"description": "Function signatures use InferSelectModel/InferInsertModel or properly typed interfaces consistent with the schema",
"max_score": 5
}
]
}