1-- Phase 9 (TASK-0104 §4, pulled forward for the TASK-0101 quota pre-check): 2-- materialized storage-quota counter on workspaces. The file service keeps it 3-- current transactionally (complete +size, purge/replace-old-versions −size); 4-- the upload-session pre-check reads it (O(1), never a live sum). 5ALTER TABLE "workspaces" ADD COLUMN "usageStorageBytes" BIGINT NOT NULL DEFAULT 0; 6 7-- Backfill (reversible no-op on re-run: idempotent recompute) — sum of 8-- non-deleted file sizes per workspace. 9UPDATE "workspaces" w 10SET "usageStorageBytes" = s.total 11FROM ( 12 SELECT "workspaceId", SUM("size") AS total 13 FROM "files" 14 WHERE "deletedAt" IS NULL 15 GROUP BY "workspaceId" 16) s 17WHERE w.id = s."workspaceId" AND s.total IS NOT NULL; 18