condo v0.1.3 Condo View Source

Main functions for Condo.

Link to this section Summary

Functions

Creates a schema

Drops a schema

Upwards migration. First checks for a change/0 function and then checks for an up/0 function

Creates a new tenant. It will first start by creating the schema, then it will ensure that there is a schema_migrations table. Once that has happened, each migration in your migration namespace will run and also write to the schema_migrations table that it has ran

Set a prefix for a query or for a tenant. If one arity is provided, we assume that the prefix is for an ID or for a struct

Rollsback the latest migration. First checks for a change/0 function and then checks for a down/0 function

Link to this section Types

Link to this type query() View Source
query() ::
  {:ok,
   %{
     :rows => nil | [[term()] | binary()],
     :num_rows => non_neg_integer(),
     optional(atom()) => any()
   }}
  | {:error, Exception.t()}
Link to this type tenant_id() View Source
tenant_id() :: String.t() | integer()

Link to this section Functions

Link to this function create_schema(repo, tenant) View Source
create_schema(queryable(), tenant_id()) :: query()

Creates a schema.

Link to this function drop_tenant(repo, tenant) View Source
drop_tenant(queryable(), tenant_id()) :: query()

Drops a schema.

Link to this function migrate_tenant(repo, tenant) View Source
migrate_tenant(queryable(), tenant_id()) :: [{:ok, non_neg_integer()}]

Upwards migration. First checks for a change/0 function and then checks for an up/0 function.

Link to this function new_tenant(repo, tenant) View Source
new_tenant(queryable(), tenant_id()) ::
  {:ok, String.t(), [{:ok, non_neg_integer()}]}

Creates a new tenant. It will first start by creating the schema, then it will ensure that there is a schema_migrations table. Once that has happened, each migration in your migration namespace will run and also write to the schema_migrations table that it has ran.

Set a prefix for a query or for a tenant. If one arity is provided, we assume that the prefix is for an ID or for a struct.

Examples

iex> prefix(123)
"tenant_123"

iex> prefix("abc")
"tenant_abc"

iex> prefix(%Blog{id: 123})
"tenant_123"

iex> from(b in Blog) |> prefix("abc")
Link to this function prefix(queryable, tenant) View Source
prefix(queryable(), tenant_id()) :: queryable()
Link to this function rollback_tenant(repo, tenant) View Source
rollback_tenant(queryable(), tenant_id()) :: {:ok, non_neg_integer()}

Rollsback the latest migration. First checks for a change/0 function and then checks for a down/0 function.