feat(db): tables for sharing pages and cloud workspaces with people and teams
Adds the tables for sharing pages and cloud workspaces with people and teams. Nothing reads or writes them yet; the API and UI ship in #8318 so either can be reverted alone.
Schema (migration 0152_sharing_people_and_teams)
page_sharesandcloud_workspace_shares: one row per grantee (a member, a team, or a pending org invitation), enforced by anum_nonnulls(...) = 1check, unique per resource and grantee.page_share_roleenum (view,comment);page_shares.roleandpages.organization_role(what general access allows), both defaulting tocommentso existing pages keep today's behaviour.cloud_workspace_activity_eventgainssharedandunshared; activity rows gaintarget_user_id,target_team_id,target_email.- Indexes on the columns that
SET NULLon delete (shared_by_user_id,target_user_id,target_team_id), added while the tables are empty.
Migration safety (.agents/skills/db-migrations)
-
Production sizes (read-only):
cloud_workspace_activity~480 rows,pages~6.8k,cloud_workspaces~280,auth.users~64k,auth.teams~66k,auth.invitations~450. No type changes or rewrites;pages.organization_roleis a metadata-onlyADD COLUMN ... DEFAULT. -
Hand-ordered (rule 3). The generated order adds columns to
pagesandcloud_workspace_activity(ACCESS EXCLUSIVE) before the new FKs take SHARE ROW EXCLUSIVE onauth.users/auth.teams, so one open writer on the auth tables stalls page reads. The migration now locks the auth tables first, while it holds only its own new tables; thecloud_workspace_activitychanges follow, andpagescomes last. A SQL comment marks each moved block; regenerating would restore the generated order. -
Rehearsed under load on fresh production-child branches, applying with
PGOPTIONS="-c lock_timeout=5s -c statement_timeout=60s"while 8 readers hitpages/auth.usersand writers held 200 ms transactions onauth.users,auth.teams, andpages:Order Applied Page reads, max Auth writes, max Generated 3/3, first attempt, ~2.6 s 955 / 1010 / 1046 ms ~1.0–1.1 s Hand-ordered (this PR) 3/3, first attempt, ~2.5 s 236 / 74 / 65 ms ~1.1–1.2 s Page-read p99 stayed at ~21 ms in every run. Writes to the auth tables still wait for the migration to commit in either order.
-
No tRPC input or output changes in this PR. Tables passed through by
findManywithoutcolumnsgain the new columns as extra output fields only. -
No
relations()for the new tables: #8318 never reads them throughdb.querywithwith.
Summary by CodeRabbit
- New Features
- Cloud workspaces can now be shared with individuals, teams, or invited people.
- Pages can be shared with individuals, teams, or invited people with view or comment access.
- Pages now support an organization-wide access level.
- Workspace activity records when a workspace is shared or unshared, including the share target.