Repository navigation
chore(db): mirror DOS-Me rate migrations, regenerate types (#1147) - #1169
Conversation
…1147) Copies seven rate-schema migrations from DOS/DOS.Me verbatim and adds the authenticator role to the replay fixture, which 20261018183000_rate_worker_role grants rate_worker to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…as (#1147) 20261023090000_rate_review_vote_eligibility reads is_anonymous, phone_confirmed_at and created_at. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…grations (#1147) Generated by pnpm gen:db-types on CI (postgres-meta v0.99.0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 14 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
⏱️ Code Review completed (10 eligible files · 88,507 chars · 4 model call(s) · 3 PR unit(s))
Whole diff with bounded context at base 645c155 / head 3ff9177.
✅ No verified defects
1 possible issue(s) could not be grounded in or verified against the snapshot source, so they are not published.
Context investigation was bounded to the explicitly requested snapshot paths.
Closes #1147
Task 1 (M0) of the item / variant / listing plan (#1129).
What
Mirrors into
supabase/migrationsthe DOS/DOS.Meratemigrations that were missing from the reference copy. Each file is byte-identical to DOS-Medev(same git blob SHA, same file name). Then it regeneratespackages/shared-data/src/database.types.ts.Files added (verbatim from DOS/DOS.Me@dev)
supabase/migrations/20261018153000_rate_row_provenance.sqlsupabase/migrations/20261018160000_rate_audit_aggregate_rpcs.sqlsupabase/migrations/20261018183000_rate_worker_role.sqlsupabase/migrations/20261020230000_rate_listing_availability.sqlsupabase/migrations/20261022140000_rate_move_iphone_16e_offer.sqlsupabase/migrations/20261023090000_rate_review_vote_eligibility.sqlsupabase/migrations/20261024060000_rate_master_min_price_plausible.sqlBefore copying, every file was scanned for secrets, passwords, keys, tokens and internal hostnames. None were found. The only URLs are public marketplace product links in fixture-URL backfill rules.
Skipped
20261025090000_rate_product_images_bucket.sqltouches only thestorageschema: a bucket plus restrictive policies onstorage.objectsandstorage.buckets. It does not touchrate, and the hermetic stack has nostorageschema.scripts/check-migration-drift.mjswill keep listing it asonly in ledger. That line is informational, does not fail the check, and is expected.dosaior other non-ratemigration. I grepped all of them forrate.; the only matches were the English word "rate" in comments and a PL/pgSQL loop variable.Other changes (no copied SQL is edited)
scripts/lib/rate-db.mjs: the Supabase-shaped fixture gains two things the new migrations need. First, anauthenticatorrole, whichrate_worker_rolegrantsrate_workerto. Second, theauth.userscolumnsis_anonymous,phone_confirmed_atandcreated_at, whichrate_review_vote_eligibilityreads.scripts/e2e/run.mjs: since the fixture now createsauthenticator, the E2E stack runsALTER ROLE ... LOGIN PASSWORDon it instead ofCREATE ROLE.packages/shared-data/src/database.types.ts: regenerated bypnpm gen:db-types. The change is additive only:originand crawl lineage columns,products.availabilityandavailability_checked_at,master_products.spec_provenance, and the RPCscurrent_user_can_vote_reviews,listing_price_context,mark_listing_unavailable,merchant_review_countsandstamp_crawl_provenance. There are no new required insert fields.Known remaining drift (out of scope, flagged)
node scripts/check-migration-drift.mjsstill reports two older files that exist in both repos but differ:20261013192302_jreviews_rating_and_review_flags.sql20261014011054_review_votes.sqlThey differ in more than comments. The DOS-Me ledger uses
IF NOT EXISTSblocks for its policies and triggers, while this copy usesDROP ... IF EXISTS+CREATE. This copy also hasREVOKE ALL ON rate.review_votes FROM anonandREVOKE EXECUTEonrate.refresh_master_product_ratingandrate.refresh_review_vote_counts, which the ledger file lacks. The task only covers newer or missing files, so this PR leaves them untouched. Someone needs to check whether prod has those REVOKEs, perhaps through a later migration.Verification
workflow_dispatchon a throwaway branch with these commits, before this PR: the migration replay passed (two passes), andE2E (Playwright)passed on the new schema (run 40552176040). This machine has no Docker, so the types file is the CIpnpm gen:db-typesoutput, unchanged. The throwaway branch is deleted.pnpm check:db-typeson the committed file, and E2E (Playwright).PR #1164
availabilityfallbackAfter this merges, the reference schema, the generated types and the E2E stack all have
rate.products.availability. Prod already has it, from DOS-Me20261020230000. anon has table-levelSELECTonrate.products, so #1164's separate, error-tolerantgetListingAvailabilityForMasterquery can be folded into the main offer select. This PR does not drop the fallback.No DDL against any live database. Nothing was written to DOS/DOS.Me.
🤖 Generated with Claude Code
📌 TL;DR
This PR implements a comprehensive data provenance and security hardening layer for the Rate database, introducing
origintracking to distinguish crawled data from synthetic/seed data, and establishing a least-privilegerate_workerrole to isolate the crawler from the sharedservice_role.🎯 Type of Change
🔍 Changes Walkthrough
packages/shared-data/src/database.types.tsorigin,last_crawled_at,spec_provenance, etc.) and new RPCs (listing_price_context,merchant_review_counts,stamp_crawl_provenance).scripts/e2e/run.mjsALTER ROLE authenticatorinstead ofCREATE ROLE, aligning with the new Supabase-shaped fixture whereauthenticatoris pre-created bystartRateDb.scripts/lib/rate-db.mjsauthenticatorrole (NOINHERIT) and expanded theauth.userstable schema to includephone_confirmed_at,is_anonymous, andcreated_atfor accurate JWT claim simulation.supabase/migrations/20261018153000_rate_row_provenance.sqlorigincolumns toproducts,reviews, andprice_history. Implemented triggers to auto-label synthetic/fixture data. Createdstamp_crawl_provenanceRPC for lineage tracking. Updated RLS policies and aggregate functions to exclude non-crawled data from public views and ratings.supabase/migrations/20261018160000_rate_audit_aggregate_rpcs.sqllisting_price_contextandmerchant_review_countsRPCs to perform complex price and review aggregations in SQL, preventing the Node.js auditor from pulling capped/incomplete data pages.supabase/migrations/20261018183000_rate_worker_role.sqlrate_workerrole. Granted specific table/RPC permissions required for the crawl cycle (ingest, queue, audit) while explicitly denying access to PII, destructive operations, and community review modifications.📊 Architectural Flow
flowchart TD subgraph Crawler [Rate-Services Crawler] A[Chromium Worker] -->|1. Ingest Data| B[rate_worker Role] end subgraph Database [PostgreSQL / Supabase] B -->|2. Write| C[(rate.products / reviews / price_history)] C -->|3. Trigger| D[Origin Labeling] D -->|4. Stamp| E[stamp_crawl_provenance RPC] subgraph Public [Public Read Layer] F[RLS Policies] -->|5. Filter origin='crawl'| G[Public API / Views] H[Aggregate RPCs] -->|6. Compute Stats| I[Master Products] end subgraph Auditor [Rate-Services Auditor] J[Node.js Auditor] -->|7. Call SQL Aggregates| H end end subgraph Security [Security Boundary] K[service_role] -.->|Blocked| B L[rate_worker] -.->|Least Privilege| C end