refactor(storage): route timestamp/interval SQL through the dialect#732
Conversation
There was a problem hiding this comment.
Pull request overview
This PR continues the mysqlstore dialect abstraction by routing current-timestamp and relative-time SQL expressions through the Dialect provider, so time arithmetic can be implemented per-database family (with MySQL output intended to remain unchanged).
Changes:
- Extend
DialectwithCurrentTimestampandRelativeTime, and implement them inMySQLDialectto render the existing MySQL/Vitess expressions. - Thread the dialect provider into
applyStore,applyOperationStore, andwebhookEventStore, and switch staleness / lease-expiry SQL to use the dialect-rendered expressions. - Add unit tests that pin the generated MySQL expressions (including placeholder counts) for the new dialect methods.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/storage/mysqlstore/dialect.go | Adds CurrentTimestamp / RelativeTime and related enums/types; implements MySQL rendering. |
| pkg/storage/mysqlstore/dialect_test.go | Adds tests pinning MySQL timestamp/interval SQL output and placeholder counts. |
| pkg/storage/mysqlstore/storage.go | Wires MySQLDialect{} into stores that now require dialect-provided time SQL. |
| pkg/storage/mysqlstore/applies.go | Routes stale-claim and retry freshness cutoffs (and a couple other relative-time predicates) through the dialect. |
| pkg/storage/mysqlstore/apply_operations.go | Routes staleness / retry freshness cutoffs through the dialect and updates the staleness constant to a typed minute count. |
| pkg/storage/mysqlstore/webhook_events.go | Routes NOW(6)/DATE_ADD usage for webhook-event claiming/heartbeat/reopen predicates through the dialect. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address Copilot review on #732: the doc comment overstated portability. Describe the seam honestly (store still emits "?" placeholders, only family-varying syntax routes through) and note the future shared-package move plus the "?"-to-"$n" rebind Postgres will need.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
🤖 Adversarial correctness review (posted on Armand's behalf by his AI agent). Verdict: clean — approve. No correctness findings. CI is green (including the integration suites that hammer the claim queries, which is the real proof for a no-behavior-change claim), and Copilot's two findings were both handled sensibly (doc honesty reword done; the The one thing that could have broken, verified byte-for-byteThe dangerous part of this refactor is positional All nine rendered sites are byte-identical to the originals: Notes (not blocking)
Verified correct
This review was generated by Claude Code (claude-fable-5). |
Migrate the NOW(6) and relative-time (INTERVAL / DATE_ADD) expressions in mysqlstore onto the Dialect provider via CurrentTimestamp/RelativeTime so a future Postgres store supplies its own syntax. Bare NOW() stamps are left untouched. No behavior change for MySQL/Vitess.
Address Copilot review on #732: the doc comment overstated portability. Describe the seam honestly (store still emits "?" placeholders, only family-varying syntax routes through) and note the future shared-package move plus the "?"-to-"$n" rebind Postgres will need.
55fcb59 to
a7bb65a
Compare
Review response from Kiran's (@Kiran01bm) AI code review assessment agent Summary: Clean approve — 0 correctness findings; two non-blocking notes, both already addressed in the #732 rebase, so nothing new is pending.
The "Verified correct" section raised no findings — all confirmations, no action. |
Summary
Continues the state-store dialect abstraction by moving the timestamp and relative-time SQL in
mysqlstorebehind theDialectprovider, so a future Postgres store can supply its own syntax. No behavior change for MySQL/Vitess.What
CurrentTimestampandRelativeTimetoDialect, withMySQLDialectrendering the exact expressions the store used before (NOW()/NOW(6),NOW() - INTERVAL n UNIT,DATE_ADD(NOW(6), INTERVAL ? MICROSECOND)).applies.goandapply_operations.go, and all fourNOW(6)/DATE_ADDsites inwebhook_events.go(FindNext claim + predicate, Heartbeat, and the redelivery-reopen predicate), through the provider.MySQLDialectinto the apply, apply-operation, and webhook-event stores.NOW()wall-clock stamps are intentionally left as-is.Why
Relative-time arithmetic is one of the last dialect-specific SQL shapes hardcoded in the state store. Centralizing it on the provider keeps the store logic engine-neutral and lets the Postgres store implement the same intent (
NOW() - INTERVAL,now() - make_interval(...), etc.) without editing every call site. Unit tests pin the generated SQL and placeholder counts so the MySQL output is provably unchanged.Before / after
Known follow-ups (out of scope, deliberately deferred)
mysqlstoreemits MySQL-style?placeholders (e.g.placeholders()inapplies.go, and the parameterizedRelativeTime). Postgres viadatabase/sqlneeds numbered placeholders ($1,$2, …). The intended approach is a single?→$nrebind at the store boundary (e.g.sqlx.Rebind) when the Postgres store lands — so theDialectseam deliberately keeps emitting?rather than growing an ordinal-placeholder API. Tracked as DB-13 in the DB-agnostic workstream; not part of this MySQL-only, no-behavior-change PR.