CodeStyle.Check.Design.NoDatabaseConstraints (code_style v0.1.1)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

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

Explanation

Avoid setting business-logic column constraints in Ecto migrations.

This check resolves direct and aliased use Ecto.Migration directives, literal import Ecto.Migration filters, and qualified Ecto migration calls in lexical source order. It analyzes each module independently and ignores quoted code.

Inside create/2 and create_if_not_exists/2 blocks it inspects add/3. Inside alter/2 blocks it inspects add/3, add_if_not_exists/3, and modify/3. The table object can be any expression.

It reports the column options :null, :default, :size, :precision, and :scale. Calls whose literal options contain primary_key: true are excluded because their defaults and sizing are structural database concerns.

Dynamic options, helper macros, remove/3, arity-one table operations, and wrapper migration modules are deliberately outside the check's scope.

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.