Jump.CredoChecks.PreferChangeOverUpDownMigrations (Jump.CredoChecks v0.3.0)

View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

Ensures Ecto migrations take advantage of automatic reversibility where possible.

When every operation in an Ecto migration's up callback is one Ecto knows how to reverse (create/alter table, create index, add / remove-with-type / modify-with-:from columns, rename, etc.), a separate down callback is redundant and can be replaced by a single change/0 callback.

# ❌ Bad
def up do
  alter table(:integration_schemas) do
    add :salesforce_record_types, :jsonb,
      null: false,
      default: fragment("'[]'::jsonb")
  end
end

def down do
  alter table(:integration_schemas) do
    remove :salesforce_record_types
  end
end

# ✅ Good
def change do
  alter table(:integration_schemas) do
    add :salesforce_record_types, :jsonb,
      null: false,
      default: fragment("'[]'::jsonb")
  end
end

For more information, see the Ecto Migration docs: https://hexdocs.pm/ecto_sql/Ecto.Migration.html

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.