Overview
File.file_size is a 32-bit IntegerField (PostgreSQL integer, max ~2.1 GB); a larger file overflows it → "integer out of range" → upload_url 500s before any bytes transfer. Widen it to 64-bit bigint, zero-downtime on the ~100M-row File table, using the migration capability from studio#5973.
Complexity: Medium
Target branch: hotfixes
Context
upload_url constructs File(file_size=size, …); a multi-GB size overflows the column and Postgres raises "integer out of range". file_size is also read/aggregated for storage accounting, check_space, and resource-size queries. A naive AlterField to bigint would rewrite the table under an ACCESS EXCLUSIVE lock — hence expand/contract.
The Change
Widen File.file_size to bigint via expand/contract on studio#5973:
- Add a nullable
bigint shadow column with a declarative dual-write trigger.
- Backfill existing rows online in batches; verify completion.
- Cut reads/aggregations to the new column behind a flag.
- Drop the old column and rename the shadow into place.
No full-table rewrite or ACCESS EXCLUSIVE lock at any step.
Out of Scope
- The reusable migration capability itself (studio#5973).
- Resumable uploads.
- Other byte-size columns (audited and tracked separately if found).
Acceptance Criteria
AI usage
I used Claude (Opus 4.8, via le-skills:writing-github-issues) to root-cause the overflow and draft this issue. The expand/contract approach was my decision; I edited for scope.
Overview
File.file_sizeis a 32-bitIntegerField(PostgreSQLinteger, max ~2.1 GB); a larger file overflows it → "integer out of range" →upload_url500s before any bytes transfer. Widen it to 64-bitbigint, zero-downtime on the ~100M-rowFiletable, using the migration capability from studio#5973.Complexity: Medium
Target branch: hotfixes
Context
upload_urlconstructsFile(file_size=size, …); a multi-GBsizeoverflows the column and Postgres raises "integer out of range".file_sizeis also read/aggregated for storage accounting,check_space, and resource-size queries. A naiveAlterFieldtobigintwould rewrite the table under anACCESS EXCLUSIVElock — hence expand/contract.The Change
Widen
File.file_sizetobigintvia expand/contract on studio#5973:bigintshadow column with a declarative dual-write trigger.No full-table rewrite or
ACCESS EXCLUSIVElock at any step.Out of Scope
Acceptance Criteria
File.file_sizeis a 64-bitbigintcolumn.Filelarger than 2.1 GB persists without "integer out of range", andupload_urlsucceeds for it.ACCESS EXCLUSIVElock.file_sizereads/aggregations (storage accounting,check_space, resource-size queries) use the widened column.AI usage
I used Claude (Opus 4.8, via
le-skills:writing-github-issues) to root-cause the overflow and draft this issue. The expand/contract approach was my decision; I edited for scope.