Skip to content

Migrate reviews to resource_edits table - #42

Merged
tayloraj10 merged 5 commits into
mainfrom
migrate-to-resource-edits-table
Aug 12, 2026
Merged

tayloraj10 merged 5 commits into
mainfrom
migrate-to-resource-edits-table

Conversation

@tayloraj10

@tayloraj10 tayloraj10 commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Migrate reviews to resource_edits (replaces broken partial rename on main)

Problem

The review dashboard (/reviews, /reviews/:id, and the dashboard summary) was built against resource_revisions, a throwaway staging table. The real table this app should build forward on is resource_edits (added in #24), which already ships the approve_edit/reject_edit/rollback_to_edit RPCs, a new-resource submission path (mapped_resource IS NULL), and ready-made review-queue views — none of which resource_revisions has.

Separately, main picked up a partial, incomplete rename to resource_edits as a side effect of an unrelated PR (#41). That version only renamed the table string and a couple of field names, but the underlying logic is still broken:

  • Approve/Reject is currently a silent no-op. The action writes to a column called status instead of review_status (the actual review-state column — status on this table is just a mirrored copy of the resource's operational status). It also never calls the RPCs, so even a "successful" click never copies the proposed changes into resources — nothing goes live on the map, and no error is shown to the reviewer.
  • No handling for brand-new site submissions (mapped_resource IS NULL) — these don't show up in the queue at all.
  • Reviewer attribution never worked, because nothing ever set reviewed_by/reviewed_at — that's why the dashboard's "Top approvers" card has been disabled with a placeholder tooltip.
  • resource_edits was missing an UPDATE policy for authenticated reviewers, so edits made on the detail page before approval (the "Save changes" button) were silently dropped by RLS.

Solution

  • Added app/api/resource-edits/methods.ts and app/types/ResourceEdit.ts (clearly named after the table they wrap), replacing app/api/resource-revisions/methods.ts and app/types/ResourceRevision.ts (deleted).
  • /reviews now merges the edit queue (resource_edits_queue) and new-resource queue (new_resources_queue) into one table, with a "Kind" (New/Edit) column.
  • /reviews/:id approve/reject now call the real approve_edit/reject_edit RPCs (capturing the reviewer's email from context.get(userContext)), so approving an edit actually applies it to resources and goes live on the map. Handles brand-new submissions without the "resource not found" warning.
  • dashboard.tsx migrated too; "Top approvers" is now live since the RPCs set reviewed_by.
  • Added supabase/migrations/20260728000000_resource_edits_update_policy.sql, the missing UPDATE policy scoped to PENDING rows for authenticated reviewers (approve/reject still must go through the RPCs — the policy's with check blocks flipping review_status directly).

Manual step before/after merge: the RLS migration above hasn't been applied to the live Supabase DB yet — this repo only has the anon key, so it needs to be run via the Supabase SQL editor or CLI with an owner/service-role credential. Until then, "Save changes" on the detail page will still silently no-op.

Reference

Closes #34. Builds on the table/RPCs added in #24.

Screenshots

N/A — no visual/UI changes, this is a data-source swap behind the existing review UI.

Checklist

  • Changes have been tested locally
  • Changes have been self-reviewed

tayloraj10 and others added 5 commits August 11, 2026 19:32
Points the app at resource_edits (approve/reject/rollback RPCs, new-resource
queue, review-queue views) instead of the throwaway resource_revisions table,
and adds the missing UPDATE policy for authenticated reviewers editing
PENDING rows before approval.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	app/api/resource-revisions/methods.ts
#	app/routes/authenticated/dashboard.tsx
#	app/routes/authenticated/reviews/detail.tsx
#	app/routes/authenticated/reviews/index.tsx
#	app/types/ResourceRevision.ts
#	app/utils/chipColors.tsx
biome check flagged import ordering and formatting drift introduced while
resolving the merge conflicts with main.

Co-authored-by: Cursor <cursoragent@cursor.com>
This change optimizes dependency handling for the @mui/icons-material package by including it in the optimizeDeps configuration. This prevents file handle exhaustion during development, particularly in environments with additional overhead like OneDrive-synced folders.
This commit adds a new entry to .gitignore for local notes and deletes the now-unnecessary next-up.md file, which contained a working list of tasks.

@RNR1 RNR1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - these comments should be addressed as follow ups, except removing the what's next doc

Comment thread docs/next-up.md Outdated
const editAPI = getResourceEditAPI(client);
const edits = await editAPI.getList();

const submitterCounts = new Map<string, number>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ideally, we run aggregation queries on the database level instead of manipulating the data in code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will fix in a future PR, have an issue to track this

revisions.map((revision) => ({
...revision,
() => [
...edits.map((edit) => ({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here - ideally the data is already prepped for usage by the time it gets here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

will fix in a future PR, have an issue to track this

@tayloraj10
tayloraj10 merged commit e60ff85 into main Aug 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Point Approval to Live Table

2 participants