0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00
logto/packages/schemas/tables/_functions.sql
2023-02-08 18:58:45 +08:00

16 lines
340 B
PL/PgSQL

/* init_order = 0.5 */
create function set_tenant_id() returns trigger as
$$ begin
select tenants.id into new.tenant_id
from tenants
where ('tenant_user_' || tenants.id) = current_user;
if new.tenant_id is null then
new.tenant_id := 'default';
end if;
return new;
end; $$ language plpgsql;
/* no_after_each */