View Source ErrorTracker.Migration behaviour (ErrorTracker v0.5.0)

Create and modify the database tables for ErrorTracker.

Usage

To use ErrorTracker migrations in your application you will need to generate a regular Ecto.Migration that performs the relevant calls to ErrorTracker.Migration.

mix ecto.gen.migration add_error_tracker

Open the generated migration file and call the up and down functions on ErrorTracker.Migration.

defmodule MyApp.Repo.Migrations.AddErrorTracker do
  use Ecto.Migration

  def up, do: ErrorTracker.Migration.up()
  def down, do: ErrorTracker.Migration.down()
end

This will run every ErrorTracker migration for your database. You can now run the migration and perform the database changes:

mix ecto.migrate

As new versions of ErrorTracker are released you may need to run additional migrations. To do this you can follow the previous process and create a new migration:

mix ecto.gen.migration update_error_tracker_to_vN

Open the generated migration file and call the up and down functions on the ErrorTracker.Migration passing the desired version.

defmodule MyApp.Repo.Migrations.UpdateErrorTrackerToVN do
  use Ecto.Migration

  def up, do: ErrorTracker.Migration.up(version: N)
  def down, do: ErrorTracker.Migration.down(version: N)
end

Then run the migrations to perform the database changes:

mix ecto.migrate

Custom prefix - PostgreSQL only

ErrorTracker supports namespacing its own tables using PostgreSQL schemas, also known as "prefixes" in Ecto. With prefixes your error tables can reside outside of your primary schema (which is usually named "public").

To use a prefix you need to specify it in your configuration:

config :error_tracker, :prefix, "custom_prefix"

Migrations will automatically create the database schema for you. If the schema does already exist the migration may fail when trying to recreate it. In such cases you can instruct ErrorTracker not to create the schema again:

defmodule MyApp.Repo.Migrations.AddErrorTracker do
  use Ecto.Migration

  def up, do: ErrorTracker.Migration.up(create_schema: false)
  def down, do: ErrorTracker.Migration.down()
end

You can also override the configured prefix in the migration:

defmodule MyApp.Repo.Migrations.AddErrorTracker do
  use Ecto.Migration

  def up, do: ErrorTracker.Migration.up(prefix: "custom_prefix")
  def down, do: ErrorTracker.Migration.down(prefix: "custom_prefix")
end

Summary

Callbacks

@callback current_version(Keyword.t()) :: non_neg_integer()
@callback down(Keyword.t()) :: :ok
@callback up(Keyword.t()) :: :ok

Functions

@spec down(Keyword.t()) :: :ok
Link to this function

migrated_version(opts \\ [])

View Source
@spec migrated_version(Keyword.t()) :: non_neg_integer()
@spec up(Keyword.t()) :: :ok