ALTER TABLE members_qualifications
    DROP FOREIGN KEY fk_members_qualifications_qualifications_id,
    DROP KEY fk_members_qualifications_qualifications_id,
    DROP COLUMN qualification_id,
    ADD COLUMN course_id INT(11) NOT NULL AFTER member_id,
    ADD COLUMN active TINYINT(1) NOT NULL DEFAULT 1,
    ADD COLUMN awarded_by_id INT(11) DEFAULT NULL,
    ADD COLUMN revoked_by_id INT(11) DEFAULT NULL,
    ADD COLUMN revoked_reason TEXT DEFAULT NULL,
    ADD COLUMN revoked_at DATETIME DEFAULT NULL,
    ADD COLUMN source_course_event_id INT(11) DEFAULT NULL,
    ADD UNIQUE KEY uq_members_qualifications_member_course (member_id, course_id),
    ADD KEY idx_members_qualifications_active (member_id, course_id, active),
    ADD KEY idx_members_qualifications_source_event (source_course_event_id),
    ADD CONSTRAINT fk_members_qualifications_course_id FOREIGN KEY (course_id) REFERENCES courses(id) ON UPDATE CASCADE,
    ADD CONSTRAINT fk_members_qualifications_awarded_by FOREIGN KEY (awarded_by_id) REFERENCES members(id) ON UPDATE CASCADE,
    ADD CONSTRAINT fk_members_qualifications_revoked_by FOREIGN KEY (revoked_by_id) REFERENCES members(id) ON UPDATE CASCADE,
    ADD CONSTRAINT fk_members_qualifications_source_event FOREIGN KEY (source_course_event_id) REFERENCES course_events(id) ON UPDATE CASCADE;
