feat(projects): tables for the client project status page (app#2048)

Merged
SW
3mo ago
+117-0

Implements the database row of recoupable/app#2048. Schema approved column-by-column in this comment after two review passes.

Contract: recoupable/docs#326, which merges first.

What this adds

One migration, four tables, nothing existing altered — no column is added to or changed on any current table.

TableColumns
projectsid, name, created_at
project_tasksid, project_id, title, description, due_date, assignee_account_id, completed_at, completed_by, created_at, updated_at
project_collaboratorsid, project_id, account_id
project_task_commentsid, task_id, account_id, body, created_at

The decisions worth reviewing

project_collaborators is the authorization model, not a directory. Three columns. A row grants one account access to one project; deleting it revokes. The api's hasProjectAccess is a single hit on the unique (project_id, account_id) index. It lives in the database rather than in a constant or an env var because every repo in this effort is public, and a client's identity cannot sit in a commit.

Keyed on account_id rather than email: an email is not reliably unique here — one address already maps to two accounts across the 1,320 account_emails rows. The cost is that access can only be granted to someone who has signed in at least once. Accepted.

assignee_account_id is what produces the client-facing "needs you" badge. The page renders it when the assignee matches the viewing account. Nothing else in the schema could distinguish a task waiting on the client from one waiting on us. A boolean would have been smaller but hard-codes that an engagement has exactly two sides.

completed_at is the completed state. No boolean to disagree with it. No CHECK pairing it with completed_by, because ON DELETE SET NULL on a removed account would violate one; a row with completed_at set and completed_by null reads correctly as "done, by someone since removed".

project_task_comments.account_id is ON DELETE RESTRICT, following credit_grants.granted_by (20260806230000). Attribution is the point of the row. Deleting an account that has commented fails loudly rather than silently orphaning what it said.

RLS on, zero policies, on all four. This matters more than usual: project_collaborators is the authorization model, so a table reachable through PostgREST with the anon key would let anyone read the allowlist or write themselves into it.

What was cut in review

projects.status and projects.updated_at (nothing renders either, and there is no project-update endpoint), projects.client_account_id (the collaborators table already answers who is on a project), project_tasks.sort_order (the timeline is created in one pass, so created_at orders it), and email / display_name / role / timestamps from the collaborators table (all recoverable from the account).

Verified before pushing

Queried production for every object this migration depends on:

  • public.trigger_set_updated_at() exists ✅
  • accounts has a primary key and accounts.id is uuid ✅
  • No name collision — none of the four table names exist today ✅
  • pgcrypto installed ✅

Branched from origin/main rather than the monorepo's submodule pointer, which sits six migrations behind.

After merge

Merging applies this to production through the Supabase GitHub integration (not Actions — this repo has no workflow files). Then types/database.types.ts needs regenerating with pnpm update-types, which unblocks the three api PRs.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BTaK5sDuryYsQG5W56mR5n


Summary by cubic

Adds four tables for the client project status page: projects, project_tasks, project_collaborators, and project_task_comments. Nothing existing is altered, and RLS is enabled with zero policies on all four; project_collaborators is the authorization model — a row grants one account access to one project, and the API guard is a single lookup on the unique (project_id, account_id) index.

Migration

  • The contract PR recoupable/docs#326 must merge first.
  • After merge, regenerate types/database.types.ts with pnpm update-types.
  • The Supabase GitHub integration applies the migration; this repo has no workflow files.

Summary by CodeRabbit

  • New Features
    • Added foundational project management data support, including projects, tasks, collaborators, and task comments.
    • Added task assignment, due dates, completion tracking, task updates, and comment length limits.
    • Added project access controls and optimized task and comment ordering.