fix: schema hygiene and SQL parameterization (COW-997, COW-998)#81
Conversation
- COW-997 [F4]: remove dead cow_cache.orderbook_cache table creation from setup.ts; table had 0 rows and 0 reads/writes — live cache is order_uid_cache - COW-998 [F6]: replace string interpolation in getCachedUidStatuses with sql.join() parameterized query, consistent with cache write pattern in same file Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The SQL parameterization change in
The legacy |
|
Review: SQL parameterization + schema hygiene
Checked drizzle-orm 0.41.0 (the installed version via pnpm, pinned transitively by ponder 0.16.2).
The legacy table creation is removed. Since this is inside # Quick check
grep -r "orderbook_cache" src/Everything else in the diff is clean. No other concerns. |
| const uidList = sql.join(batch.map((uid) => sql`${uid}`), sql`, `); | ||
| const rows = (await context.db.sql.execute( | ||
| sql.raw( | ||
| `SELECT order_uid, status, executed_sell_amount, executed_buy_amount | ||
| FROM cow_cache.order_uid_cache | ||
| WHERE chain_id = ${chainId} AND order_uid IN (${placeholders})`, | ||
| ), | ||
| sql`SELECT order_uid, status, executed_sell_amount, executed_buy_amount | ||
| FROM cow_cache.order_uid_cache | ||
| WHERE chain_id = ${chainId} AND order_uid IN (${uidList})`, |
There was a problem hiding this comment.
would prefer something like:
const rows = await context.db.sql
.select({
orderUid: orderUidCache.orderUid,
status: orderUidCache.status,
executedSellAmount: orderUidCache.executedSellAmount,
executedBuyAmount: orderUidCache.executedBuyAmount,
})
.from(orderUidCache)
.where(
and(
eq(orderUidCache.chainId, chainId),
inArray(orderUidCache.orderUid, batch),
),
);
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e is not a direct dep Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… add drizzle-orm as direct dep Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replaces the remaining raw sql\` template in orderbookClient.ts with .insert().onConflictDoUpdate() using the already-defined orderUidCacheTable. Also drops the now-unused `sql` named import from ponder. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- blockHandler.ts: 3× sql\`${col} IS NULL\` → isNull(col); adds isNull import
- execution-summary.ts: sql\`SELECT … GROUP BY\` → .select().from().where().groupBy()
using discreteOrder table and count() operator; drops Number() cast
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…able suffix) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…998-schema-and-sql-hygiene
Handler was converted from db.execute(sql\`GROUP BY\`) to db.select().from().where().groupBy() with count() from ponder. Update mocks accordingly: ponder:api now exposes db.select, ponder exports and/eq/count, and StatusRow.count is number not string. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Two small hygiene fixes from the grant review targeting dead schema and inconsistent SQL patterns.
Changes
src/application/handlers/setup.ts— remove thecow_cache.orderbook_cacheCREATE TABLE block. The table had 0 rows and 0 reads/writes anywhere in the codebase; the live persistent cache iscow_cache.order_uid_cache. Also updated the file-level doc comment which referenced the removed table.src/application/helpers/orderbookClient.ts— replace manual string interpolation ('${uid.replace(...)}') withsql.join(batch.map(uid => sql\${uid}`), sql`, `)ingetCachedUidStatuses`. Now consistent with the parameterized pattern used for cache writes in the same file.How to Test
pnpm typecheck— no errorspnpm test— all tests passChecklist
Breaking Changes
None —
orderbook_cachehad no rows and no consumers. Thesql.joinproduces semantically identical queries with bound parameters instead of interpolated strings.Related Issues
Closes COW-997
Closes COW-998