MDL-38228 upgrade: Rewrite and re-apply script that fixes corrupt course modules to sequence relation