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