Skip to content

feat!: Add Container.container_code field#545

Draft
kdmccormick wants to merge 4 commits intokdmccormick/keys-componentfrom
kdmccormick/keys-container
Draft

feat!: Add Container.container_code field#545
kdmccormick wants to merge 4 commits intokdmccormick/keys-componentfrom
kdmccormick/keys-container

Conversation

@kdmccormick
Copy link
Copy Markdown
Member

@kdmccormick kdmccormick commented Apr 15, 2026

Description

Adds a container_code field (code_field) and a learning_package FK to the Container model. Also adds a UniqueConstraint on (learning_package, container_code), which is stricter than Component's constraint (no type scoping -- container codes must be unique across all container types within a given LearningPackage).

For existing containers, container_code is backfilled from the entity key via a data migration. Future containers will have container_code set explicitly by the caller.

Backup/restore now writes container_code into the [entity.container] section (Verawood and later). Archives created in Ulmo (which have no container_code) fall back to using the entity key as the container_code on restore.

BREAKING CHANGE: create_container() and create_container_and_version() now require a container_code keyword argument. The same applies to create_unit_and_version(), create_subsection_and_version(), and create_section_and_version().

Part of: #322

Full series of PRs:

  1. feat!: Collection.key -> Collection.collection_code #542
  2. feat!: Component.local_key -> Component.component_code #544
  3. feat!: Add Container.container_code field #545
  4. feat!: Package and Entity keys are now opaque refs #546
  5. feat!: ComponentVersionMedia.key -> ComponentVersionMedia.path #547

Testing

TBC

AI disclosure

Claude helped me write this PR. See #322 for details.

Also, standardize internal usage of collection_key to collection_code.
This helps clarify that Collection.key is *not* an OpaqueKey, but is rather
a local slug, which can be combined with other identifiers to form a fully-
qualified LibraryCollectionKey instance.

BREAKING CHANGE: Collection.key has been renamed to Collection.collection_code.

BREAKING CHANGE: Collection.collection_code now validates that its contents
matches '[A-Za-z0-9\-\_\.]+'.  This was already effectively true, because
LibraryCollectionKey can only be built with slug-like parts, but we now
we explicitly raise ValiationError from create_collection.

Backup now writes both 'key' and 'collection_code' to collection TOML files,
so older software (which only knows 'key') can still read new archives.
Restore accepts either field, preferring 'collection_code' and falling back
to the legacy 'key'.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Part of: #322
@kdmccormick kdmccormick force-pushed the kdmccormick/keys-container branch from 62746d6 to 845c3c7 Compare April 15, 2026 09:56
Renames the Component.local_key field to component_code, switching
from key_field() to code_field() (stricter validation: [A-Za-z0-9\-\_\.]+,
max_length=255). Updates all API call sites, backup/restore, and tests.

Backup/restore now writes an [entity.component] section in each component
TOML file containing component_type and component_code explicitly, so that
restore does not need to parse the entity key. Old archives (without the
[entity.component] section) are still accepted by falling back to the
existing entity key parsing.

BREAKING CHANGE: Component.local_key has been renamed to Component.component_code.

BREAKING CHANGE: Component.component_code now validates against
[A-Za-z0-9\-\_\.]+  and has a max_length of 255. Previously local_key
used key_field() (no regex validation, max_length=500).

BREAKING CHANGE: Function parameters renamed from local_key to component_code
in create_component(...) and create_component_and_version(...).

BREAKING CHANGE: Functions get_component_by_key(...)/component_exists_by_key(...),
renamed to get_component_by_code(...)/component_exists_by_code(...), and
parameters renamed from local_key to component_code.

Part of: #322

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kdmccormick kdmccormick force-pushed the kdmccormick/keys-component branch from 944a2c3 to fbe4b4b Compare April 15, 2026 10:06
@kdmccormick kdmccormick force-pushed the kdmccormick/keys-container branch from 845c3c7 to fbe4b4b Compare April 15, 2026 10:07
@kdmccormick kdmccormick reopened this Apr 15, 2026
Adds a container_code field (code_field) and a learning_package FK to the
Container model. Also adds a UniqueConstraint on (learning_package,
container_code), which is stricter than Component's constraint
(no type scoping -- container codes must be unique across all container
types within a given LearningPackage).

For existing containers, container_code is backfilled from the entity key
via a data migration. Future containers will have container_code set
explicitly by the caller.

Backup/restore now writes container_code into the [entity.container]
section (Verawood and later). Archives created in Ulmo (which have no
container_code) fall back to using the entity key as the container_code
on restore.

BREAKING CHANGE: create_container() and create_container_and_version()
now require a container_code keyword argument. The same applies to
create_unit_and_version(), create_subsection_and_version(), and
create_section_and_version().

Part of: #322

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kdmccormick kdmccormick force-pushed the kdmccormick/keys-container branch from 0f70804 to 266d7f3 Compare April 15, 2026 10:18
learning_package_id: LearningPackage.ID,
key: str,
*,
container_code: str,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that this has key and container_code is just from how the PRs are split up right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

@kdmccormick kdmccormick force-pushed the kdmccormick/keys-component branch from fbe4b4b to f4d32b8 Compare April 16, 2026 18:18
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.

2 participants