Skip to content

feat: sync course filters from MongoDB to MySQL on course publish#143

Merged
igobranco merged 5 commits into
nau/teak.masterfrom
crls/feat/analytics_course_filters
May 25, 2026
Merged

feat: sync course filters from MongoDB to MySQL on course publish#143
igobranco merged 5 commits into
nau/teak.masterfrom
crls/feat/analytics_course_filters

Conversation

@ccantillo

Copy link
Copy Markdown
Contributor

Course filters for analytics

Summary

This change mirrors enrollment and certificate filter flags from MongoDB (other_course_settings) into a new MySQL table whenever a course is published in Studio, so nau-database-exporter can expose them in Looker Studio without connecting to MongoDB.

Related context: NAU technical proposal / dashboard work (e.g. fccn/nau-technical#635, customer requirement: course filters visible in analytics).


Problem

Filter settings such as domain-based enrollment, NIF requirement, and Portuguese citizen card for certificates live only in MongoDB. The existing exporter reads MySQL only, so dashboards cannot tell which courses are effectively restricted for all learners.


Solution

  • Model NauCourseFilter: course_id, filter_type, timestamps; unique_together on (course_id, filter_type); one row per active filter.
  • Sync on publish: Handler on CMS SignalHandler.course_published reads normalized other_course_settings, creates missing rows, deletes rows for filters no longer active. Errors are logged and never block publishing.
  • Configurable keys: Default keys: filter_enrollment_by_domain_list, filter_enrollment_require_nif, certificate_require_portuguese_citizen_card. Override via NAU_COURSE_FILTER_KEYS for future filters.
  • Backfill: Management command sync_course_filters (CMS) for all courses, a single course (--course-id), or resume (--index).
  • Admin: Django admin registration for inspection and support.
  • Tests: Unit tests for sync logic (create/delete/partial/falsy/idempotent/errors) and handler (calls sync, swallows unexpected exceptions).

Deployment notes

  1. Deploy nau-openedx-extensions with migration 0012_naucoursefilter.
  2. Run migrations on the Open edX MySQL database.
  3. Run python manage.py cms sync_course_filters once to backfill historical courses (optionally chunked with --index).
  4. Follow-up (separate repo/PR): extend nau-database-exporter to join or query NauCourseFilter and add the desired boolean or denormalized columns for Looker Studio.

@ccantillo ccantillo requested review from Alec4r and efortish April 14, 2026 23:39
ccantillo added 5 commits May 25, 2026 11:47
Add NauCourseFilter model and course_published signal handler to mirror
enrollment/certificate filter settings (other_course_settings) into MySQL,
so nau-database-exporter can expose them in Looker Studio without MongoDB access.
Includes backfill management command and unit tests.
@igobranco igobranco force-pushed the crls/feat/analytics_course_filters branch from d5dc6a6 to 085caed Compare May 25, 2026 10:57
@igobranco igobranco self-requested a review May 25, 2026 12:35
@igobranco

Copy link
Copy Markdown
Member

Fixed the conflict.
Tested locally and it has worked fine.
Approving and Merging.

@igobranco igobranco merged commit 5cbaa32 into nau/teak.master May 25, 2026
3 checks passed
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