ALTER TABLE children
  ADD COLUMN member_id INT NULL AFTER id;

UPDATE children c
INNER JOIN line_members lm ON lm.line_user_id = c.line_user_id
SET c.member_id = lm.id
WHERE c.member_id IS NULL;

ALTER TABLE children
  ADD INDEX idx_children_member_id (member_id);

ALTER TABLE children
  ADD CONSTRAINT fk_children_member_id
  FOREIGN KEY (member_id)
  REFERENCES line_members(id)
  ON DELETE CASCADE;

ALTER TABLE children
  MODIFY member_id INT NOT NULL;

ALTER TABLE children
  ADD UNIQUE KEY uq_children_member_name (member_id, name);

ALTER TABLE children
  DROP INDEX idx_children_line_user_id;

ALTER TABLE children
  DROP COLUMN line_user_id;
