Skip to content

Fix media uploads rejected with a 0 byte storage quota - #91

Merged
HafizMMoaz merged 1 commit into
mainfrom
fix/media-storage-limit-quota
Jul 27, 2026
Merged

Fix media uploads rejected with a 0 byte storage quota#91
HafizMMoaz merged 1 commit into
mainfrom
fix/media-storage-limit-quota

Conversation

@HafizMMoaz

Copy link
Copy Markdown
Member

Fixes #89

Root cause

PlanSeeder created all three plans without storage_limit, so they landed on the column default of 0. assignPlan() copies the plan's limit onto the company, so every company on a seeded plan carried a 0 byte quota and MediaController::checkStorageLimit() rejected the very first upload with "Storage limit exceeded. Please delete files or upgrade plan".

A second bug lived in the same check: collect($files)->sum('size') reads a size property that UploadedFile does not have, so it always returned 0 and the incoming upload was never weighed against the limit. Only already-stored files counted.

Changes

  • PlanSeeder: free/starter/professional now ship with 5/25/100 GB.
  • Migration 2026_07_27_000001_backfill_plan_storage_limits: gives existing 0 quota plans 5 GB and re-syncs companies stuck on 0, so live installs recover without an admin editing every plan by hand.
  • MediaController::checkStorageLimit(): sum getSize() so the upload actually counts.
  • Store/UpdatePlanRequest: storage_limit min 1 GB, a 0 GB plan is not a usable plan.

Verification

  • tests/Feature/MediaStorageLimitTest.php: upload succeeds under a real quota, is rejected when the incoming file exceeds it (this one fails without the getSize() fix), and a 0 GB plan no longer validates.
  • Full suite: 13 failures before and after the change, all pre-existing; the 3 new tests pass.
  • Driven in the local app end to end: with the company on a 0 quota the upload returns the exact 422 from the issue, and after picking up the plan's new 5 GB limit the same PDF uploads and appears in the library.

🤖 Generated with Claude Code

Every seeded plan was created without storage_limit, so it fell to the
column default of 0. Companies subscribed to one inherited a 0 byte quota
and the first media upload failed with "Storage limit exceeded". Seed the
three plans with real limits (5/25/100 GB) and backfill installs that
already have 0 quota plans and companies.

The quota check itself never counted the incoming upload either:
sum('size') on UploadedFile objects reads a property that does not exist
and always returned 0, so only files already stored were weighed. Sum
getSize() instead.

Plans can no longer be saved with a 0 GB limit, which is what produced
the dead quota in the first place.

Fixes #89
@HafizMMoaz
HafizMMoaz requested a review from a team as a code owner July 27, 2026 00:01
@HafizMMoaz
HafizMMoaz merged commit 4c14ebc into main Jul 27, 2026
1 check passed
@HafizMMoaz
HafizMMoaz deleted the fix/media-storage-limit-quota branch July 27, 2026 00:05
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.

Unable to Upload Files on Media Library Page

1 participant