Carbonite.Migrations (Carbonite v0.4.0) View Source

Functions to setup Carbonite audit trails in your migrations.

Link to this section Summary

Functions

Inserts an outbox record into the database.

Installs a change capture trigger on a table.

Rollback a migration.

Removes an outbox record.

Removes a change capture trigger from a table.

Allows to update a trigger configuration option for a given table.

Runs one of Carbonite's migrations.

Link to this section Types

Specs

down_option() :: {:carbonite_prefix, prefix()} | {:drop_schema, boolean()}

Specs

outbox_name() :: String.t()

Specs

outbox_option() :: {:carbonite_prefix, prefix()}

Specs

patch() :: non_neg_integer()

Specs

prefix() :: binary()

Specs

table_name() :: binary() | atom()

Specs

trigger_config_key() ::
  :table_prefix | :primary_key_columns | :excluded_columns | :mode

Specs

trigger_option() :: {:table_prefix, prefix()} | {:carbonite_prefix, prefix()}

Specs

up_option() :: {:carbonite_prefix, prefix()}

Link to this section Functions

Link to this function

create_outbox(outbox_name, opts \\ [])

View Source (since 0.4.0)

Specs

create_outbox(outbox_name(), [outbox_option()]) :: :ok

Inserts an outbox record into the database.

Options

  • carbonite_prefix is the schema of the audit trail, defaults to "carbonite_default"
Link to this function

create_trigger(table_name, opts \\ [])

View Source (since 0.4.0)

Specs

create_trigger(table_name(), [trigger_option()]) :: :ok

Installs a change capture trigger on a table.

Options

  • table_prefix is the name of the schema the table lives in
  • carbonite_prefix is the schema of the audit trail, defaults to "carbonite_default"
Link to this function

down(patch, opts \\ [])

View Source (since 0.4.0)

Specs

down(patch(), [down_option()]) :: :ok

Rollback a migration.

Options

  • carbonite_prefix defines the audit trail's schema, defaults to "carbonite_default"
  • drop_schema controls whether the initial migration deletes the schema during rollback
Link to this function

drop_outbox(outbox_name, opts \\ [])

View Source (since 0.4.0)

Specs

drop_outbox(outbox_name(), [outbox_option()]) :: :ok

Removes an outbox record.

Options

  • carbonite_prefix is the schema of the audit trail, defaults to "carbonite_default"
Link to this function

drop_trigger(table_name, opts \\ [])

View Source (since 0.4.0)

Specs

drop_trigger(table_name(), [trigger_option()]) :: :ok

Removes a change capture trigger from a table.

Options

  • table_prefix is the name of the schema the table lives in
  • carbonite_prefix is the schema of the audit trail, defaults to "carbonite_default"
Link to this function

put_trigger_config(table_name, key, value, opts \\ [])

View Source (since 0.4.0)

Specs

put_trigger_config(table_name(), trigger_config_key(), any(), [trigger_option()]) ::
  :ok

Allows to update a trigger configuration option for a given table.

This function builds an SQL UPDATE statement that can be used within a database migration to update a setting stored in Carbonite's triggers table without using the Carbonite.Trigger schema or other application-level code that is prone to change over time. This helps to ensure that your data migrations continue to function, regardless of future updates to Carbonite.

Configuration values

  • primary_key_columns is a list of columns that form the primary key of the table
                      (defaults to `["id"]`, set to `[]` to disable)
  • excluded_columns is a list of columns to exclude from change captures
  • filtered_columns is a list of columns that appear as '[FILTERED]' in the data
  • mode is either :capture or :ignore and defines the default behaviour of the trigger

Example

Carbonite.Migrations.put_trigger_config("rabbits", :excluded_columns, ["name"])

Options

  • table_prefix is the name of the schema the table lives in
  • carbonite_prefix is the schema of the audit trail, defaults to "carbonite_default"
Link to this function

up(patch, opts \\ [])

View Source (since 0.4.0)

Specs

up(patch(), [up_option()]) :: :ok

Runs one of Carbonite's migrations.

Migration patchlevels

Make sure that you run all migrations in your host application.

  • Initial patch: 1
  • Current patch: 2

Options

  • carbonite_prefix defines the audit trail's schema, defaults to "carbonite_default"