Rbtz.CredoChecks.Refactor.PreferTextColumns (rbtz_credo_checks v0.2.0)

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 normal and works with any version of Elixir.

Explanation

Ensures that Ecto migrations use :text rather than :string for column types.

In modern versions of PostgreSQL there is no storage or performance benefit to textual columns with a fixed maximum length. It is almost always preferable to leave the maximum length unset in the database and enforce length limits as a business rule at the application level via changeset validations.

Bad

add :name, :string
modify :description, :string

Good

add :name, :text
modify :description, :text

Like all Design issues, this one is not a technical concern. It encodes a project-wide convention; disable per-line with # credo:disable-for-next-line when a fixed-length column is genuinely required (e.g. legacy schemas, foreign keys to immutable identifiers).

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.