This is one followup of
Just to avoid the course_completion_aggr_methd to become out of control it could be interesting to create one unique index on it by the course and criteriatype, to enforce that uniqueness from DB constraint.
But there is one problem and it's that criteriatype is nullable, some some DBs will allow duplicates having that column null. So the complete plan is:
1) Consider changing that null to 0 (current values and column specs) and make all the changes in logic needed to support that.
2) Create the unique index (surely cleaning any duplicate again, just in case a new one has arrived, although it should not).
That is, something for DEV backlog exclusively 100%. Ciao