Published · 1 min read
Tenant isolation the database enforces
In a multi-tenant product the failure that matters most is one customer seeing another's data. Row-level security is the usual defense, and Pulse AI uses it on every business table. But a filter only decides what a query returns. It does not stop a buggy write from linking a contact in one workspace to a company in another.
Make the wrong reference impossible
Every child table references its parent through a composite key that includes the workspace. A contact does not point at a company by id alone, but by id and workspace together, and the database checks that pair. A row that tries to cross workspaces is rejected by the foreign key before any policy is consulted.
-- Tenant integrity is enforced structurally: every child references its parent
-- through a composite FK (id, workspace_id), so rows can never point across
-- workspaces even if application code is wrong.
-- (id, organization_id) on workspaces lets children pin both tenant keys at once.
alter table public.workspaces add constraint workspaces_id_org_key unique (id, organization_id);
-- ... in the contacts table:
unique (id, workspace_id),
foreign key (workspace_id, organization_id)
references public.workspaces (id, organization_id) on delete cascade,
foreign key (company_id, workspace_id)
references public.companies (id, workspace_id) on delete set null (company_id)Policies on top
Row-level security is enabled on every business table, with one policy per operation instead of a single catch-all. The helper functions the policies call live in a private schema that the data API does not expose.
The server never accepts an organization or workspace id from the client. It resolves the workspace from the session and derives the ids from there. The service role, which bypasses policies, is used only where no user session exists: the scheduled dispatcher and signed machine-to-machine webhooks.
Tested like any other behavior
Isolation is covered by tests that run against a real database inside a transaction and roll back. The security document counts 92 cross-tenant and role tests. They assert what an outsider cannot do, not only what a member can.
it("other tenants and members without workspace access see nothing", () => /* ... */);
it("a member without access to the workspace cannot write even within the same org", () => /* ... */);
it("composite FKs block cross-workspace references", () => /* ... */);
it("only owner/admin hard-delete contacts", () => /* ... */);
it("users cannot forge system timeline events", () => /* ... */);In CI, a dedicated job starts a local database, applies the migrations, runs the platform's security advisors and then these tests.
A limit worth stating
Production and preview deployments share one database, so a preview with new migrations touches production data. It is listed among the project's known risks.