mocha/sql/mysql/000-functions/mocha_get_instance_by_global_identifier.sql

13 lines
525 B
SQL

DROP FUNCTION IF EXISTS mocha_get_instance_by_global_identifier;
CREATE FUNCTION mocha_get_instance_by_global_identifier
(
p_global_identifier CHAR(40)
)
RETURNS INT
DETERMINISTIC
RETURN (
SELECT id FROM mocha_instances
WHERE (tenant_id = mocha_get_current_tenant() OR tenant_id IN (SELECT target_tenant_id FROM mocha_tenant_references WHERE source_tenant_id = mocha_get_current_tenant()))
AND mocha_normalize_uuid(global_identifier) = mocha_normalize_uuid(p_global_identifier)
ORDER BY id DESC LIMIT 1);