Skip to content

basalt / tenancy-prisma/src / PrismaTenantSource

Class: PrismaTenantSource ​

Defined in: tenancy-prisma/src/index.ts:108

Where tenants are loaded from — the app's database in production.

Implements ​

Constructors ​

Constructor ​

> new PrismaTenantSource(client, options?): PrismaTenantSource

Defined in: tenancy-prisma/src/index.ts:111

Parameters ​

client ​

PrismaTenancyClient

options? ​

PrismaTenantSourceOptions = {}

Returns ​

PrismaTenantSource

Methods ​

create() ​

> create(tenant): Promise<Tenant>

Defined in: tenancy-prisma/src/index.ts:164

Insert a NEW tenant and its custom-domain set; an existing id throws TenantAlreadyExistsError and leaves that tenant untouched.

A plain create, not a find-then-upsert: the primary key is what refuses the duplicate, so of two concurrent creates of the same id exactly one wins — which no read in application code can guarantee. This is what tenancy.create() calls.

Same transaction as save: a domain conflict leaves no tenant behind.

Parameters ​

tenant ​

Tenant

Returns ​

Promise<Tenant>

Implementation of ​

TenantSource.create


delete() ​

> delete(id): Promise<void>

Defined in: tenancy-prisma/src/index.ts:228

Removes a tenant; its domains cascade (schema onDelete: Cascade).

This is the TenantSource.delete the contract asks for, and what tenancy.destroy() calls. Without it, destroy refuses — which is the right answer, and not one you want to meet in production.

Parameters ​

id ​

string

Returns ​

Promise<void>

Implementation of ​

TenantSource.delete


find() ​

> find(id): Promise<Tenant | null>

Defined in: tenancy-prisma/src/index.ts:206

Parameters ​

id ​

string

Returns ​

Promise<Tenant | null>

Implementation of ​

TenantSource.find


findByDomain() ​

> findByDomain(domain): Promise<Tenant | null>

Defined in: tenancy-prisma/src/index.ts:211

Required by the domain resolver (custom domains).

Parameters ​

domain ​

string

Returns ​

Promise<Tenant | null>

Implementation of ​

TenantSource.findByDomain


list() ​

> list(): Promise<Tenant[]>

Defined in: tenancy-prisma/src/index.ts:216

Required by tenancy.forEach() and basalt tenant:list.

Returns ​

Promise<Tenant[]>

Implementation of ​

TenantSource.list


remove() ​

> remove(id): Promise<boolean>

Defined in: tenancy-prisma/src/index.ts:233

The older name, kept so existing callers keep working.

Parameters ​

id ​

string

Returns ​

Promise<boolean>


save() ​

> save(tenant): Promise<Tenant>

Defined in: tenancy-prisma/src/index.ts:139

Insert or update a tenant and replace its custom-domain set. Domains are globally unique — a domain already owned by a different tenant is rejected, and nothing is written.

The record and its domain set are written in ONE transaction: a failure part-way (a domain another tenant claimed in the meantime, a lost connection) rolls the whole save back instead of leaving the tenant rewritten with its domains deleted. The tenant row is written first, so two concurrent saves of the same tenant serialise on its row lock.

An upsert replaces the whole record. That is right for an intentional update and for status transitions; it is wrong for creating a tenant, which is what create is for.

Parameters ​

tenant ​

Tenant

Returns ​

Promise<Tenant>

Implementation of ​

TenantSource.save

Released under the MIT License.