CREATE OR REPLACE FUNCTION updateMioloUserFromBasperson(p_personid INT, p_oldLogin TEXT)
/**
  NAME: updateMioloUserFromBasperson
  DESCRIPTION: Edita campos do usuário na miolo_user com base em dados da basperson

  REVISIONS:
  Ver        Date        Author                Description
  ---------  ----------- --------------------  ------------------------------------
  1.0        21/10/2025  Daniel A. Corbellini  1. Função criada.
*/
RETURNS void AS $$
BEGIN
  UPDATE miolo_user AS mu
  SET
    name = bp.name,
    nickname = bp.name,
    login = bp.miolousername,
    m_password = md5(bp.password),
    confirm_hash = md5(bp.password)
  FROM basperson AS bp
  WHERE mu.login = p_oldLogin
    AND bp.personid = p_personid;
END;
$$ LANGUAGE plpgsql;