This is just an idea for now; it may be pretty low importance unless we learn that these issues have actually happened.
Many aspects of our data models are required to be a certain way, but we cannot make the database enforce that directly (without using triggers). We try to validate these things using clean() etc. but those checks are not always run (e.g. when using update()).
To help avoid and diagnose issues, we could write checks that use the Django system check framework to inspect the database and verify the integrity of our models.
Database checks are not run by default because they do more than static code analysis as regular checks do. They are only run by the migrate command or if you specify configured database aliases using the --database option when calling the check command.
~Django docs
Alternately, such validation checks could be written as a Django management command, or even a REST API that provides tooling and reporting via the admin console.
Issues that such system checks could look for:
LearningPackage with no corresponding course/library (warning, not error)
PublishableEntity with no corresponding Component/Container/etc.
component.learning_package_id != component.publishable_entity.learning_package_id
component_version.component.publishable_entity_id != component_version.publishable_entity_version.entity_id
container_version.container.publishable_entity_id != container_version.publishable_entity_version.entity_id
publish_log_record.entity.learning_package_id != publish_log_record.publish_log.learning_package_id
draft_change_log_record.entity.learning_package_id != draft_change_log_record.draft_change_log.learning_package_id
collection_publishable_entity.entity.learning_package_id != collection_publishable_entity.collection.learning_package_id
component_version_media.component_version.component.learning_package_id != component_version_media.media.learning_package_id
This is just an idea for now; it may be pretty low importance unless we learn that these issues have actually happened.
Many aspects of our data models are required to be a certain way, but we cannot make the database enforce that directly (without using triggers). We try to validate these things using
clean()etc. but those checks are not always run (e.g. when usingupdate()).To help avoid and diagnose issues, we could write checks that use the Django system check framework to inspect the database and verify the integrity of our models.
~Django docs
Alternately, such validation checks could be written as a Django management command, or even a REST API that provides tooling and reporting via the admin console.
Issues that such system checks could look for:
LearningPackagewith no corresponding course/library (warning, not error)PublishableEntitywith no corresponding Component/Container/etc.component.learning_package_id != component.publishable_entity.learning_package_idcomponent_version.component.publishable_entity_id != component_version.publishable_entity_version.entity_idcontainer_version.container.publishable_entity_id != container_version.publishable_entity_version.entity_idpublish_log_record.entity.learning_package_id != publish_log_record.publish_log.learning_package_iddraft_change_log_record.entity.learning_package_id != draft_change_log_record.draft_change_log.learning_package_idcollection_publishable_entity.entity.learning_package_id != collection_publishable_entity.collection.learning_package_idcomponent_version_media.component_version.component.learning_package_id != component_version_media.media.learning_package_id