Add missing foreign keys

Add missing foreign keys to job_metadata and schedule_metadata. Check
whether the foreign keys are existing. If not, then add.