Ecto 3.10
Last reviewed Oct 25, 2026
Prompt Details
Prompt Composition
3prompts
- Erlang/OTP 29187 lines · 8.9K tokens
- Elixir 1.2051 lines · 1.6K tokens
- Ecto 3.1053 lines · 1.8K tokens
Total291 lines · 12.3K tokens
CWE Coverage
- 20
- 22
- 59
- 78
- 89
- 95
- 116
- 117
- 190
- 204
- 208
- 209
- 214
- 250
- 287
- 295
- 296
- 297
- 298
- 299
- 306
- 307
- 319
- 323
- 327
- 338
- 347
- 352
- 362
- 367
- 379
- 400
- 407
- 427
- 444
- 470
- 494
- 502
- 522
- 532
- 611
- 613
- 639
- 664
- 674
- 732
- 755
- 770
- 772
- 789
- 799
- 807
- 829
- 834
- 862
- 863
- 915
- 916
- 918
- 922
- 942
- 943
- 1287
- 1395
Prompt Preview
Apply the Elixir 1.20 and Erlang/OTP 29 prompts first. These rules cover Ecto 3.10 with Ecto SQL 3.10 and Postgrex: changesets, queries, repositories, transactions, tenancy, database connections, and migrations.
Changesets
- Write the permitted fields of every
cast/4call as a literal list, with separate changesets for separate roles and forms. Never compute it from params keys,__schema__(:fields), or request input. - Leave tenant, owner, role, price, balance, and approval fields out of user-facing
cast/4lists and set them from the authenticated context. Ecto 3.10 can't mark a field read-only, so add a test that a forged value in an update is ignored. - Reserve
change/2,put_change/3,force_change/3, andput_assoc/4for server-built values; they skip casting and field filtering. - Set
redact: trueon secret-bearing fields to hide them from struct and changeset inspection. Query logs and telemetry still contain their raw values. - Cast children through
cast_assoc/3orcast_embed/3with an explicit:withchangeset, after preloading only children the user may edit.on_replace: :deleteor:delete_if_existsdeletes a child the params leave out. The:drop_paramand:sort_paramoptions, new in 3.10, let the request delete children by index and add entries for unknown indexes, so turn them on only where the user may do both to every preloaded child. - Back
unsafe_validate_unique/4with a unique index andunique_constraint/3; the pre-check races. Pass a tenant-scoped:querywhen uniqueness is per tenant, or the check matches other tenants'