Skip to content

chore(db): mirror the review ai points migration - #1600

Merged
JOY (JOY) merged 1 commit into
devfrom
chore/1531-mirror-review-ai-points
Nov 3, 2026
Merged

JOY (JOY) merged 1 commit into
devfrom
chore/1531-mirror-review-ai-points

Conversation

@JOY

@JOY JOY (JOY) commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Refs #1531

Mirrors the review AI points migration, which DOS.Me applied to production through DOS.Me#1553 (merge 069105a7).

  • supabase/migrations/20261106120000_rate_review_ai_points.sql is copied byte for byte from DOS.Me main (30336 bytes).
  • packages/shared-data/src/database.types.ts is regenerated with pnpm gen:db-types. It adds review_ai_batches, review_ai_extractions, store_review_ai_points, purge_review_ai_points and review_ai_text_hash.
  • scripts/test-review-ai-points-proposal.mjs already rolls the migration back first when the reference stack has it, so the proposal replay keeps running on the mirrored stack.

The local Docker replays were not waited on; CI runs the same replays.

🤖 Generated with Claude Code


📌 TL;DR

This PR introduces the database schema and logic for the AI Review Points feature, adding tables to track AI batch processing costs and extraction markers, along with secure RPC functions to validate, store, and purge AI-generated review insights.

🎯 Type of Change

  • 🚀 New feature
  • 🐛 Bugfix
  • 🧹 Refactor
  • ⚡ Performance
  • 📚 Documentation
  • ⚙️ CI / Configuration

🔍 Changes Walkthrough

File Summary of Changes
packages/shared-data/src/database.types.ts Updates TypeScript type definitions to reflect the new review_ai_batches and review_ai_extractions tables, including their row structures, relationships, and the new purge_review_ai_points, review_ai_text_hash, and store_review_ai_points functions.
supabase/migrations/20261106120000_rate_review_ai_points.sql Implements the core database logic:
1. Tables: Creates review_ai_batches (cost tracking/manifests) and review_ai_extractions (process-once markers per review).
2. Security: Configures RLS policies restricting writes to service_role and rate_worker.
3. Functions: Adds review_ai_text_hash (NFC-normalized SHA256), store_review_ai_points (validates AI output against strict criteria like length, duplicates, and evidence quotes before writing), and purge_review_ai_points (removes AI lines/markers by version).

📊 Architectural Flow

sequenceDiagram
    participant Job as AI Job (rate_worker)
    participant DB as Supabase DB
    participant Batches as review_ai_batches
    participant Extractions as review_ai_extractions
    participant Points as review_points

    Note over Job, DB: 1. Batch Submission
    Job->>Batches: INSERT batch record (id, manifest, reserved_cost)
    
    Note over Job, DB: 2. Processing & Validation
    Job->>DB: Call store_review_ai_points(p_rows)
    activate DB
    DB->>DB: Validate shape, criteria, length, duplicates
    DB->>DB: Check review status (crawl, no writer lines, hash match)
    
    alt Valid AI Points
        DB->>Points: DELETE existing 'ai' lines
        DB->>Points: INSERT new 'ai' lines
        DB->>Extractions: UPSERT marker (outcome: 'stored')
    else Failed/Empty/Rejected
        DB->>Extractions: UPSERT marker (outcome: 'failed'/'empty'/'rejected')
    end
    deactivate DB
    DB-->>Job: Return counts (stored, failed, etc.)

    Note over Job, DB: 3. Batch Completion
    Job->>Batches: UPDATE batch (status: 'stored', cost_usd)

    Note over Job, DB: 4. Purge (Optional)
    Job->>DB: Call purge_review_ai_points(version)
    activate DB
    DB->>Points: DELETE 'ai' lines for version
    DB->>Extractions: DELETE markers for version
    deactivate DB
Loading

Summary by CodeRabbit

  • New Features
    • Added support for processing AI-generated points from reviews, with safeguards to prevent outdated or invalid results from replacing existing content.
    • Review processing outcomes and batch costs can now be tracked.
    • AI-generated review points can be cleared either in full or by prompt version.

DOS.Me applied 20261106120000_rate_review_ai_points.sql to production
(DOS.Me#1553, merge 069105a7). The file is copied byte for byte from
DOS.Me main, and database.types.ts is regenerated: review_ai_batches,
review_ai_extractions and the three functions.

Refs #1531

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
rate Ready Ready Preview Nov 3, 2026 8:18pm UTC

Request Review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

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.

@github-actions github-actions Bot added area:shared Shared packages / contracts / configs area:database labels Nov 3, 2026
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

The migration adds batch and extraction tables, a text-hash function, and functions to validate, store, and purge AI review points. Generated database types describe the new tables and functions.

Changes: AI review points

Layer / File(s) Summary
Batch and extraction storage
supabase/migrations/20261106120000_rate_review_ai_points.sql, packages/shared-data/src/database.types.ts
The migration creates batch and per-review extraction tables with constraints, indexes, and role-specific access. Database types add their row, insert, update, and relationship shapes.
Validate and store extraction results
supabase/migrations/20261106120000_rate_review_ai_points.sql, packages/shared-data/src/database.types.ts
The migration adds an NFC-normalized text hash and a writer that validates inputs, checks review eligibility, records failed attempts, and stores extraction outcomes and AI lines. Database types describe the hash and writer functions.
Purge AI review data
supabase/migrations/20261106120000_rate_review_ai_points.sql, packages/shared-data/src/database.types.ts
The purge function removes AI lines and extraction markers for all data or a selected prompt version, then returns deletion counts. Its function type is added to the database types.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Other

Sequence Diagram(s)

sequenceDiagram
  participant Worker as rate_worker
  participant Writer as rate.store_review_ai_points
  participant Reviews as rate.reviews
  participant Points as rate.review_points
  participant Markers as rate.review_ai_extractions
  Worker->>Writer: Submit rows as JSON
  Writer->>Reviews: Lock and check eligible reviews
  Writer->>Points: Replace AI lines for non-failed results
  Writer->>Markers: Record extraction outcome
  Writer-->>Worker: Return per-row results
Loading

Possibly related issues

Possibly related PRs

  • DOS/Rate#1597: Proposes the same AI review-points tables, functions, validation, and purge behavior implemented here.
  • DOS/Rate#1599: Implements a job that creates batches and calls the storage function added by this migration.
  • DOS/Rate#1576: Adds rating criteria and review-text helpers that this migration uses for validation.

Suggested labels: area:database, area:shared

Suggested reviewers: dos

Merge Risk: Low · up to 7295f

Overlapping purge and extraction operations can cause unnecessary repeat API processing. Address the purge race or prevent concurrent execution; the remaining risk is bounded.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/shared-data/src/database.types.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

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.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

dos[bot]
dos Bot approved these changes Nov 3, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Code Review completed (2 eligible files · 36,246 chars · 4 model call(s) · 2 PR unit(s))

Whole diff with bounded context at base f7435b1 / head 7295f6f.

✅ CLEAN_PASS: Complete diff reviewed

Context investigation was bounded to the explicitly requested snapshot paths.

@JOY
JOY (JOY) merged commit 37ea3c8 into dev Nov 3, 2026
20 of 21 checks passed
@JOY
JOY (JOY) deleted the chore/1531-mirror-review-ai-points branch November 3, 2026 20:26
@JOY JOY (JOY) mentioned this pull request Nov 4, 2026
2 of 6 tasks

This branch was successfully deployed

1 active deployment
Preview — 7295f6fb Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:database area:shared Shared packages / contracts / configs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant