ALTER TABLE assignments
  ADD COLUMN event_id INT NULL AFTER id,
  ADD COLUMN event_slot_id INT NULL AFTER event_id;

UPDATE assignments a
INNER JOIN slots s ON s.id = a.slot_id
SET
  a.event_id = s.event_id,
  a.event_slot_id = s.event_slot_id;

ALTER TABLE assignments
  MODIFY COLUMN event_id INT NOT NULL,
  MODIFY COLUMN event_slot_id INT NOT NULL;

ALTER TABLE assignments
  DROP FOREIGN KEY fk_assignments_slot_id,
  DROP INDEX uq_assignments_slot_child,
  DROP INDEX idx_assignments_slot_id,
  ADD CONSTRAINT fk_assignments_event_slot_ref FOREIGN KEY (event_id, event_slot_id) REFERENCES slots(event_id, event_slot_id) ON DELETE CASCADE,
  ADD UNIQUE KEY uq_assignments_event_slot_child (event_id, event_slot_id, child_id),
  ADD INDEX idx_assignments_event_slot_ref (event_id, event_slot_id);

ALTER TABLE assignments
  DROP COLUMN slot_id;

ALTER TABLE slots
  DROP PRIMARY KEY,
  DROP INDEX uq_slots_event_local_id,
  DROP COLUMN id,
  ADD PRIMARY KEY (event_id, event_slot_id);
