condo v0.2.4 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()

View Source
tenant() :: tenant_id() | %{id: tenant_id()}
Link to this type

tenant_id()

View Source
tenant_id() :: String.t() | integer() | atom()

Link to this section Functions

Link to this function

create_schema(repo, tenant)

View Source
create_schema(queryable(), tenant()) :: query()

Creates a schema.

Link to this function

drop_tenant(repo, tenant)

View Source
drop_tenant(queryable(), tenant()) :: query()

Drops a schema.

Link to this function

migrate_tenant(repo, tenant)

View Source
migrate_tenant(queryable(), tenant()) :: [{: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()) ::
  {: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> Condo.prefix("public")
"public"

iex> Condo.prefix(:public)
"public"

iex> Condo.prefix(123)
"tenant_123"

iex> Condo.prefix("abc")
"tenant_abc"

iex> Condo.prefix(:abc)
"tenant_abc"

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

iex> Condo.prefix("users", :abc)
#Ecto.Query<from u0 in "users">
Link to this function

prefix(queryable, tenant)

View Source
prefix(queryable(), tenant()) :: queryable()
Link to this function

rollback_tenant(repo, tenant)

View Source
rollback_tenant(queryable(), tenant()) :: {:ok, non_neg_integer()}

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