Fix incorrectly dropped procedure
Migration 29 in [405d7121f59fd1a48b9f1c81e71e727bb3858dc5] accidentally dropped the user_ids_from_cohort_and_master_group stored procedure.

This changes fixes migration 29 and also adds migration 31 to restore the procedure anywhere it was already dropped.