Widen LocalFile.file_size to 64-bit for files larger than 2.1 GB
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Overview
Kolibri's LocalFile.file_size is a 32-bit IntegerField (base_models.py:209), capping file sizes at ~2.1 GB. This widens it to 64-bit so Kolibri can store and import content larger than 2.1 GB.
Complexity: Medium Target branch: develop
Context
Kolibri gates content imports on min_schema_version, not the schema version a channel was published at (channel_import.py:1218, :1228). A channel published at a newer schema still imports on older Kolibri as long as its min_schema_version is one that Kolibri supports.
Studio will keep the legacy 32-bit file_size column in the exported content database alongside a new 64-bit column, populating the legacy column with NULL when a file exceeds 2.1 GB. This is what lets min_schema_version stay at the current value: old Kolibri reads the legacy column (degraded to NULL size for oversized files it can't use anyway), new Kolibri reads the 64-bit column.
The import mapper resolves columns by name (channel_import.py:437), so renaming file_size → file_size_bigint defeats it for every database published before the rename: those carry a file_size column, and the new destination column file_size_bigint is absent from their rows, so file sizes would import as NULL. Those versions need an explicit per-version mapping (see below). The content export schemas (contentschema/versions/) are generated from the Django model, not hand-written; there is also a separate current destination schema that import writes into.
The Change
Widen LocalFile.file_size from IntegerField to BigIntegerField with db_column="file_size_bigint" — the Python attribute stays file_size (no call-site churn), but the underlying column is renamed. The rename is deliberate: it gives new Kolibri a distinct column to read, leaving the legacy file_size column for Studio to populate for old clients. A single column widened in place couldn't serve both readers.
Existing file_size values must be preserved into file_size_bigint, and the data copy must not run inside the migration. The choreography:
- Migration adds
file_size_bigint, retainsfile_size, and removesfile_sizefrom Django's model/migration state. - The physical
DROP COLUMNis conditional on table data: ifLocalFileis empty (fresh install), dropfile_sizeinline in the migration; if it has rows (existing install), leave the column in place and defer. - The content upgrade task (
kolibri/core/content/upgrade.py,@version_upgrade) copiesfile_size→file_size_bigint, then drops the now-orphanedfile_sizecolumn on existing installs.
Because file_size is removed from migration state unconditionally, makemigrations sees a stable schema on both paths; only the physical column's drop timing differs, gated on whether there's data to preserve.
The rename also defeats the by-name import mapper for content databases published before it. Add a per_row mapping file_size_bigint ← file_size on LocalFile for the import classes covering VERSION_5 and earlier (mappings, channel_import.py:1188). VERSION_5 currently maps to the bare ChannelImport with no mappings, so this means a new intermediate import class, with NoLearningActivitiesChannelImport inheriting the same mapping. The new export version maps to the bare ChannelImport, which works by name because new exports carry file_size_bigint.
Regenerate the schema from the changed model: bump CONTENT_SCHEMA_VERSION (leave MIN_CONTENT_SCHEMA_VERSION) for the new export version, and regenerate the current destination schema (content_schema_current.py) so it reflects file_size_bigint.
Out of Scope
- Studio-side publishing changes (writing both columns, skip-small-on-overflow).
- Zero-downtime / online-backfill migration machinery — Kolibri's
LocalFiletable is per-device; a standard migration plus upgrade task suffices. - Renaming the
file_sizePython attribute or touching its call sites —db_columnkeeps the attribute name stable.
Acceptance Criteria
General
- [ ]
LocalFile.file_sizeis aBigIntegerFieldbacked bydb_column="file_size_bigint"; the Python attribute remainsfile_size. - [ ] A
file_sizevalue above 2.1 GB persists and reads back correctly on both SQLite and PostgreSQL backends. - [ ] After a fresh install, the
LocalFiletable hasfile_size_bigintand nofile_sizecolumn, andmakemigrationsreports no pending changes. - [ ] Upgrading from a prior version preserves existing
file_sizevalues intofile_size_bigint, then dropsfile_size. - [ ] Django's recorded migration state matches the physical table on both the fresh-install and upgrade paths.
- [ ]
CONTENT_SCHEMA_VERSIONis bumped with a newly generated export schema;MIN_CONTENT_SCHEMA_VERSIONis unchanged. - [ ]
content_schema_current.pyreflectsfile_size_bigint. - [ ] An import-class
per_rowmapping populatesfile_size_bigintfrom the legacyfile_sizecolumn for databases published at VERSION_5 and earlier; importing one lands file sizes infile_size_bigint.
Testing
- [ ] Test: importing a pre-rename content database lands file sizes in
file_size_bigint. - [ ] Test: the upgrade task copies
file_sizeintofile_size_bigintand dropsfile_size. - [ ] Test: a >2.1 GB file size round-trips through import and serialization.
References
kolibri/core/content/base_models.py—LocalFile.file_sizedefinitionkolibri/core/content/upgrade.py—@version_upgradetask patternkolibri/core/content/utils/channel_import.py— per-version column mappingkolibri/core/content/constants/schema_versions.py—CONTENT_SCHEMA_VERSION
AI usage
I used Claude (Opus 4.8, via le-skills:writing-github-issues) to draft this issue. The design — dual-column rename, deferred drop via upgrade task, conditional fresh-vs-upgrade migration choreography — was mine; Claude grounded the claims against the content app's import, upgrade, and schema-version code and wrote them up. I edited throughout and cut over-specification.
Plan: Widen LocalFile.file_size from IntegerField to BigIntegerField(db_column="file_size_bigint") so Kolibri can store and import content files larger than 2.1 GB.
- [ ] Model field change + migration
- [ ] Schema version bump + regenerate content schema files
- [ ] Import class mapping for pre-rename databases
- [ ] Upgrade task for existing installs
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?
- Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
- Ran the project's full test suite and linter before committing
- For UI changes: captured live screenshots to verify rendering
- For backend changes: verified with example API/CLI output
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.