1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//! Tenant-scoped session-variable helper for the RLS-enforced
//! `graph_nodes` + `graph_edges` tables (invariant #11 defense
//! in depth, mirroring's treatment of the
//! `entelix-persistence` tables).
//!
//! Every tenant-scoped query opens a transaction, calls
//! [`set_tenant_session`] to stamp `entelix.tenant_id` for the
//! duration of the transaction, runs its query, and commits.
//! `set_config(name, value, true)` mirrors `SET LOCAL` semantics
//! — the variable is scoped to the enclosing transaction; pool
//! connections that return to the pool carry no leftover state.
//!
//! See `crates/entelix-persistence/src/postgres/tenant.rs` for the
//! sibling helper used by the SDK's other Postgres-backed
//! storage tables.
use TenantId;
use Error;
use Executor;
use Postgres;
use cratePgGraphMemoryError;
/// Stamp the current transaction's `entelix.tenant_id` session
/// variable. The third argument to `set_config` is `is_local =
/// true`, scoping the assignment to the enclosing transaction
/// (mirrors `SET LOCAL` semantics). Takes the typed [`TenantId`]
/// so the policy cannot be armed with a tenantless value.
pub async