Skip to content

Implement a system check to verify integrity of our data models? #556

@bradenmacdonald

Description

@bradenmacdonald

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions