DROP PROCEDURE IF EXISTS mocha_get_instance_by_global_identifier;

CREATE PROCEDURE mocha_get_instance_by_global_identifier
(
    IN p_global_identifier CHAR(40)
)
BEGIN

    SELECT * FROM mocha_instances
    WHERE tenant_id = mocha_get_current_tenant()
    AND UPPER(global_identifier) = UPPER(REPLACE(REPLACE(REPLACE(p_global_identifier, '{', ''), '}', ''), '-', ''))
    LIMIT 1;

END;
