Skip to main content

lib/kryptex/postgres_migration.ex

defmodule Kryptex.PostgresMigration do
  @moduledoc """
  Postgres migration helpers.

  The encrypted field type stores binary payloads, so in Postgres this maps to
  `bytea` via Ecto's `:binary`.
  """

  defmacro __using__(_opts) do
    quote do
      import Kryptex.PostgresMigration
    end
  end

  @doc """
  Adds an encrypted column (`:binary` / `bytea`) to a Postgres table.
  """
  defmacro add_encrypted(name, opts \\ []) do
    quote do
      add(unquote(name), :binary, unquote(opts))
    end
  end
end