PhoenixMountable.Migration.Helpers (PhoenixMountable v0.2.1)

Copy Markdown View Source

Functions imported in PhoenixMountable.Migration modules.

Summary

Functions

Adds a column to a table unless it exists, on every adapter (MySQL has no ADD COLUMN IF NOT EXISTS).

Registers or runs a backfill. See PhoenixMountable.Backfill.

Whether a column exists in a table of the context's prefix.

Creates an index without locking writes on Postgres (CREATE INDEX CONCURRENTLY), and normally on other databases.

Creates an index unless one with its name exists, on every adapter.

Drops an index if it exists, without locking writes on Postgres. See create_concurrently/1.

Drops an index if one with its name exists, on every adapter.

The column type of a foreign key to a library table: :binary_id or :bigint, matching primary_key/1.

The primary key options chosen at install time, for library tables

Recreates a SQLite table with changed columns, keeping every column, index and trigger the host added. See PhoenixMountable.Migrations.SQLite.

Whether a table exists in the context's prefix.

Functions

add_column_if_missing(ctx, table, column, type, opts \\ [])

Adds a column to a table unless it exists, on every adapter (MySQL has no ADD COLUMN IF NOT EXISTS).

add_column_if_missing(ctx, :my_lib_items, :slug, :string)

backfill(ctx, backfill)

Registers or runs a backfill. See PhoenixMountable.Backfill.

column_exists?(ctx, table, column)

Whether a column exists in a table of the context's prefix.

create_concurrently(index)

Creates an index without locking writes on Postgres (CREATE INDEX CONCURRENTLY), and normally on other databases.

A version using it runs outside a transaction on Postgres. The generator adds @disable_ddl_transaction true and @disable_migration_lock true to the host's migration for it.

create_index_if_missing(index)

Creates an index unless one with its name exists, on every adapter.

MySQL has no CREATE INDEX IF NOT EXISTS, so Ecto's create_if_not_exists raises there. This checks first, which keeps a version safe to run again after a partial failure (MySQL DDL is not transactional).

drop_concurrently(index)

Drops an index if it exists, without locking writes on Postgres. See create_concurrently/1.

drop_index_if_present(index)

Drops an index if one with its name exists, on every adapter.

key_type(ctx)

The column type of a foreign key to a library table: :binary_id or :bigint, matching primary_key/1.

add :item_id, references(:my_lib_items, type: key_type(ctx), prefix: ctx.prefix)

primary_key(ctx)

The primary key options chosen at install time, for library tables:

create table(:my_lib_items, primary_key: primary_key(ctx), prefix: ctx.prefix)

[name: :id, type: :binary_id] when installed with primary_key: :binary_id, otherwise [name: :id, type: :bigserial].

rebuild_table(ctx, table, changes)

Recreates a SQLite table with changed columns, keeping every column, index and trigger the host added. See PhoenixMountable.Migrations.SQLite.

table_exists?(ctx, table)

Whether a table exists in the context's prefix.