OptimumCredo.Check.Refactor.SchemaTableNameMismatch (OptimumCredo v0.5.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 low and works with any version of Elixir.

Explanation

Name the schema after its table (singular of the table name).

Bad

defmodule MyApp.Quiz.Question do
  use Ecto.Schema

  schema "user_questions" do
  end
end

Good

defmodule MyApp.Quiz.Question do
  use Ecto.Schema

  schema "questions" do
  end
end

Legacy tables can opt out with @credo_table_name_ok true in the module.

Check-Specific Parameters

Use the following parameters to configure this check:

:allow_context_prefix

Accept a table named <context>_<plural of schema>, for example library_follows for Library.Follow.

This parameter defaults to false.

:custom_inflections

Map of singular => plural snake_case words for irregular domain words.

This parameter defaults to %{}.

General Parameters

Like with all checks, general params can be applied.

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