# `Bylaw.Ecto.Query.Checks.UnboundedUpdates`
[🔗](https://github.com/ryanzidago/bylaw/blob/v0.1.0-alpha.1/lib/bylaw/ecto/query/checks/unbounded_updates.ex#L1)

Validates that `update_all` queries are bounded.

This check is useful as a guard against accidentally updating every row in a
table.

## Examples

Bad:

    from(Post, as: :post)
    |> update(set: [archived: true])

Why this is bad:

An `update_all` query without a root predicate can update every row in the
table.

Better:

    from(Post, as: :post)
    |> where([post: p], p.status == ^:draft)
    |> where([post: p], p.updated_at < ^cutoff)
    |> update(set: [archived: true])

Why this is better:

The root `where` clauses state the intended update scope.

## Notes

This check only requires a non-true root predicate. It does not prove the
predicate is selective or semantically correct.

The check only applies to the `:update_all` operation reported by
`c:Ecto.Repo.prepare_query/3`. It requires every possible root `where` branch
to include at least one non-true expression. It does not prove whether that
predicate is selective. Checks that need specific predicates should use a more
targeted rule such as
`Bylaw.Ecto.Query.Checks.MandatoryWhereKeys`.

## Options

  * `:validate` - explicit `false` disables the check. Defaults to `true`.

## Usage

Add this module to the explicit check list passed through `Bylaw.Ecto.Query`.
See `Bylaw.Ecto.Query` for the full `c:Ecto.Repo.prepare_query/3` setup.

# `validate`

```elixir
@spec validate(
  Bylaw.Ecto.Query.Check.operation(),
  Bylaw.Ecto.Query.Check.query(),
  opts()
) ::
  Bylaw.Ecto.Query.Check.result()
```

Implements the `Bylaw.Ecto.Query.Check` validation callback.

---

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