Mutiny (mutiny v0.1.0) View Source

Functions for generating database commands that enforce immutability.

Link to this section Summary

Functions

Injects shorthand Mutiny functions that implicitly pass the specified adapter. These functions include

Returns a function that can be executed to prevent UPDATEs to a database table. This function only needs to be executed once per database.

Drops the function created by create_prevent_update_function/0, if it exists. Useful when rolling back a migration.

Returns a command to create a database trigger that prevents UPDATEs to the given Ecto.Migration.Table.

Returns a command to create a database trigger that prevents UPDATEs to the given columns of the Ecto.Migration.Table.

Link to this section Functions

Link to this macro

__using__(opts)

View Source (macro)

Specs

__using__(opts :: keyword()) :: Macro.t()

Injects shorthand Mutiny functions that implicitly pass the specified adapter. These functions include:

  • protect/1 - Makes a table immutable
  • protect/3 - Makes specific columns of a table immutable
  • create_prevent_update_function/0 - Creates the database function Mutiny calls
  • drop_prevent_update_function/0 - Drops the database function Mutiny calls

When useing this module, a database adapter module should be specified. The currently available modules are:

Note that Mutiny exposes public versions of all these functions, should you desire to call them directly.

Options

  • adapter - The Mutiny database adapter to use

Examples

defmodule MyApp.Repo.Migrations.CreateSnapshots do
  use Ecto.Migration
  use Mutiny, adapter: Mutiny.Adapter.Postgres

  create table("snapshots") do
    add :data, :map
  end

  protect(table("snapshots"))
end
Link to this function

create_prevent_update_function(adapter)

View Source

Specs

create_prevent_update_function(atom()) :: String.t()

Returns a function that can be executed to prevent UPDATEs to a database table. This function only needs to be executed once per database.

Examples

iex> Mutiny.Adapters.Postgres ...> |> create_prevent_update_function() ...> |> execute() :ok

Link to this function

drop_prevent_update_function(adapter)

View Source

Specs

drop_prevent_update_function(atom()) :: String.t()

Drops the function created by create_prevent_update_function/0, if it exists. Useful when rolling back a migration.

Examples

iex> Mutiny.Adapters.Postgres ...> |> drop_prevent_update_function() ...> |> execute() :ok

Specs

protect(Ecto.Migration.Table.t(), atom()) :: String.t()

Returns a command to create a database trigger that prevents UPDATEs to the given Ecto.Migration.Table.

An adapter module that implements Mutiny.Adapter should be specified in correspondence with your Ecto adapter.

Examples

iex> table("users")
...> |> protect(Mutiny.Postgres)
...> |> execute()
:ok
Link to this function

protect(table, columns, adapter, opts \\ [])

View Source

Specs

Returns a command to create a database trigger that prevents UPDATEs to the given columns of the Ecto.Migration.Table.

An adapter module that implements Mutiny.Adapter should be specified in correspondence with your Ecto adapter.

Options may be specified as an opts list that will be passed to the given adapter.

Examples

iex> table("users")
...> |> protect([:uuid, :birthdate], Mutiny.Adapters.Postgres)
...> |> execute()
:ok

iex> table("users")
...> |> protect([:uuid], Mutiny.Adapters.Postgres, nullable: true)
...> |> execute()
:ok