Repository navigation
feat(db): add generated availability_zone column and 9-column recommendations index - #808
Conversation
…ndations index Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Warning Review limit reached
This review includes 3 billable files and costs up to $0.75.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Or wait 3 minutes for your next included review. View limit details
Comment |
Gate review (Opus 5.5, independent): CHANGES REQUESTED at 9ef9c32Blocker: CI Fix: Migration review (clean):
Local evidence (throwaway PostgreSQL 17.11 on 127.0.0.1, scratch DB,
Re-gate after the lint fix lands and CI is green. |
|
Fixed govet shadow in the 000109 test at c21611e (golangci-lint with go1.26.9 and the integration tag: no issues). Waiting on CI. |
Gate verdict (Opus 5.5, independent): APPROVED at c21611e
Merging with |
Part of #792 (PR2a of the zonal EC2 AZ work; PR1 is #807). Migration only, no Go store change.
What
Migration 000109 adds
recommendations.availability_zoneasGENERATED ALWAYS AS (COALESCE(payload->>'availability_zone', payload->'details'->>'availability_zone', '')) STOREDand a new unique indexrecommendations_natural_key_az_idxon the existing 8 key columns plusavailability_zone. The existing 8-columnrecommendations_natural_key_idxis kept, so the currentON CONFLICTupsert keeps working for old and new code. Down drops the new index and the column.Existing rows are backfilled by the table rewrite from either payload shape (top-level field, or
details.availability_zonefor rows written before the top-level field existed); everything else becomes ''.Known limitation (resolved in PR2c)
Two zonal rows differing only by AZ are still rejected by the kept 8-column index. The migration test documents this.
Lock impact
Adding a stored generated column rewrites the table, and the index build blocks writes.
CREATE INDEX CONCURRENTLYis not possible because the runner wraps every migration in a transaction. The table is a regenerable cache repopulated every collection cycle, so this is acceptable.Prod runbook
database-migration.ymlfor this PR (PR2a) before releasing PR2b.Dev auto-migrates on merge.
Verification
TestMigration_RecommendationsAvailabilityZone(up/down, backfill from legacy-details-only, both-shapes, top-level-only, regional and no-details rows, 8-column upsert still works, AZ-only pair still rejected by the 8-column index, index definition, rollback). Run locally against PostgreSQL 17 (the test body with a direct pool; testcontainers hangs on this machine), not through the container helper; CI runs the real one.detailsfallback fails the test; droppingavailability_zonefrom the new index fails the index-definition assertion.🤖 Generated with Claude Code