DripDrop.Tenants (DripDrop v0.3.3)

Copy Markdown View Source

Tenant-wide data operations.

delete_tenant/1 removes every DripDrop row a tenant owns, for hosts that delete an account. Every delete is filtered by tenant_key, so global rows (tenant_key: nil) and other tenants' rows are never selected.

Summary

Functions

Deletes every DripDrop row owned by tenant_key in one transaction.

Types

cross_tenant_reference()

@type cross_tenant_reference() :: %{
  table: String.t(),
  column: atom(),
  count: pos_integer()
}

Functions

delete_tenant(tenant_key)

@spec delete_tenant(String.t()) ::
  {:ok, %{required(atom()) => non_neg_integer()}}
  | {:error, {:cross_tenant_references, [cross_tenant_reference()]}}

Deletes every DripDrop row owned by tenant_key in one transaction.

Returns the deleted row count per table. When a row outside the tenant references one of the tenant's rows, nothing is deleted and the references are returned, since the delete would otherwise change that row too.

tenant_key must be a non-blank string; global rows cannot be deleted through this function.