kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

Widen LocalFile.file_size to 64-bit for files larger than 2.1 GB

Open rtibbles opened this issue 5 months ago • 9 comments

❌ 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, retains file_size, and removes file_size from Django's model/migration state.
  • The physical DROP COLUMN is conditional on table data: if LocalFile is empty (fresh install), drop file_size inline 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) copies file_size → file_size_bigint, then drops the now-orphaned file_size column 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 LocalFile table is per-device; a standard migration plus upgrade task suffices.
  • Renaming the file_size Python attribute or touching its call sites — db_column keeps the attribute name stable.

Acceptance Criteria

General

  • [ ] LocalFile.file_size is a BigIntegerField backed by db_column="file_size_bigint"; the Python attribute remains file_size.
  • [ ] A file_size value above 2.1 GB persists and reads back correctly on both SQLite and PostgreSQL backends.
  • [ ] After a fresh install, the LocalFile table has file_size_bigint and no file_size column, and makemigrations reports no pending changes.
  • [ ] Upgrading from a prior version preserves existing file_size values into file_size_bigint, then drops file_size.
  • [ ] Django's recorded migration state matches the physical table on both the fresh-install and upgrade paths.
  • [ ] CONTENT_SCHEMA_VERSION is bumped with a newly generated export schema; MIN_CONTENT_SCHEMA_VERSION is unchanged.
  • [ ] content_schema_current.py reflects file_size_bigint.
  • [ ] An import-class per_row mapping populates file_size_bigint from the legacy file_size column for databases published at VERSION_5 and earlier; importing one lands file sizes in file_size_bigint.

Testing

  • [ ] Test: importing a pre-rename content database lands file sizes in file_size_bigint.
  • [ ] Test: the upgrade task copies file_size into file_size_bigint and drops file_size.
  • [ ] Test: a >2.1 GB file size round-trips through import and serialization.

References

  • kolibri/core/content/base_models.py — LocalFile.file_size definition
  • kolibri/core/content/upgrade.py — @version_upgrade task pattern
  • kolibri/core/content/utils/channel_import.py — per-version column mapping
  • kolibri/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.

rtibbles avatar Jun 24 '26 19:06 rtibbles

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

status


@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

rtibblesbot avatar Jun 25 '26 01:06 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jun 25 '26 06:06 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jun 26 '26 06:06 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 03 '26 07:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 04 '26 04:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 13 '26 07:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 14 '26 02:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 14 '26 19:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 18 '26 20:07 rtibblesbot