2023-01-28 06:26:29 -05:00
|
|
|
/* init_order = 0.5 */
|
|
|
|
|
2024-03-20 00:16:23 -05:00
|
|
|
/** A function to set the tenant_id column based on the current user. */
|
2023-01-28 06:26:29 -05:00
|
|
|
create function set_tenant_id() returns trigger as
|
|
|
|
$$ begin
|
2023-02-10 00:06:52 -05:00
|
|
|
if new.tenant_id is not null then
|
|
|
|
return new;
|
2023-01-28 06:26:29 -05:00
|
|
|
end if;
|
|
|
|
|
2023-02-10 00:06:52 -05:00
|
|
|
select tenants.id into new.tenant_id
|
|
|
|
from tenants
|
|
|
|
where tenants.db_user = current_user;
|
|
|
|
|
2023-01-28 06:26:29 -05:00
|
|
|
return new;
|
|
|
|
end; $$ language plpgsql;
|
2023-02-08 05:58:45 -05:00
|
|
|
|
2024-03-21 10:10:24 -05:00
|
|
|
/** A function to set the `updated_at` column to the current time. */
|
2024-03-20 00:16:23 -05:00
|
|
|
create function set_updated_at() returns trigger as
|
|
|
|
$$ begin
|
|
|
|
new.updated_at = now();
|
|
|
|
return new;
|
|
|
|
end; $$ language plpgsql;
|
|
|
|
|
2023-02-08 05:58:45 -05:00
|
|
|
/* no_after_each */
|