# `EctoDoctor`
[🔗](https://github.com/Daniel-Brai/ecto-doctor/blob/v0.0.1/lib/ecto_doctor.ex#L1)

Finds where your Ecto schemas and changesets disagree with your database.

Most people run it with `mix ecto.doctor`.
Call `diagnose/2` to use the findings in your own code.

    {:ok, findings} = EctoDoctor.diagnose(MyApp.Repo)

It reads your schemas through reflection and your changesets from source.
Then it reads the live database and compares the three.
Nothing is written.

## Options

* `:apps` (list of `t:atom/0`) - Picks the apps whose schemas are checked. Defaults to the repo's app.

* `:only` - Runs only these checks.

* `:except` - Skips these checks. The default value is `[]`.

* `:all` (`t:boolean/0`) - Reports info level findings too. The default value is `false`.

* `:checks` - Sets options for single checks. `false` turns a check off and `ignore` takes table or column patterns. The default value is `[]`.

* `:ignore_tables` (list of `t:String.t/0`) - Leaves these tables out of every check. One `*` matches anything. The default value is `["schema_migrations", "oban_*"]`.

* `:baseline` - Leaves out the findings listed in this file. Set it to nil to report everything. The default value is `".ecto_doctor_baseline.exs"`.

## Config file

`mix ecto.doctor` also reads `.ecto_doctor.exs` from the project root.
It holds the same options as a keyword list.

    [
      checks: [orphan_table: [ignore: ["legacy_*"]], string_length_overflow: false],
      ignore_tables: ["schema_migrations", "oban_*", "pg_search_documents"]
    ]

A schema can also turn checks off for itself with a comment like `# ecto_doctor:ignore missing_not_null` inside its module.

# `diagnose`

```elixir
@spec diagnose(Ecto.Repo.t(), keyword()) ::
  {:ok, [EctoDoctor.Finding.t()]} | {:error, EctoDoctor.Error.t()}
```

Runs every check against the repo and returns the findings with the most severe first.

Findings listed in the baseline file are left out.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
