# `Ash.Seed`
[🔗](https://github.com/ash-project/ash/blob/v3.23.1/lib/ash/seed.ex#L5)

Helpers for seeding data, useful for quickly creating lots of data either for database seeding or testing.

Important: this bypasses resource actions, and goes straight to the data layer. No action changes or validations are run.
The only thing that it does at the moment is ensure that default values for attributes are set, it does not validate
that required attributes are set (although the data layer may do that for you, e.g with ash_postgres).

# `keep_nil`

Returns `:__keep_nil__`, allowing to ensure a default value is not used when you want the value to be `nil`.

# `seed!`

Seed using a record (instance of a resource) as input.

If the passed in struct was retrieved from the data layer already (i.e already seeded),
then it is returned and nothing is done. Otherwise, the attributes and relationships are
used as input to `seed/2`, after having any `%Ash.NotLoaded{}` values stripped out.

Any `nil` values will be overwritten with their default values. To avoid this, either use `seed/2`
in which providing the key will have it not set the default values.
If you want to force `nil` to be accepted and prevent the default value from being set, use the
`keep_nil/0` function provided here, which returns `:__keep_nil__`. Alternatively, use
`seed!(Post, %{text: nil})`.

See `seed!/2` for more information.

# `seed!`

Performs a direct call to the data layer of a resource with the provided input.

If a list is provided as input, then you will get back that many results.

To set a tenant, use the tenant option.

# `skip`

Returns `:__skip__`, allowing to ensure no value is generated for a given field when used with generators.

# `update!`

Usage is the same as `seed!/2`, but it will update an existing record.

For multitenant resources, tenant will be extracted from the record if
not provided in opts.

# `upsert!`

Performs an upsert operation on the data layer of a resource with the provided input and identities.
The usage is the same as `seed!/1`, but it will update the record if it already exists.

```elixir
Ash.Seed.upsert!(%User{email: 'test@gmail.com', name: 'Test'}, identity: :email)
```

# `upsert!`

Usage is the same as `seed!/2`, but it will update the record if it already exists based on the identities.

---

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