Skip to content

Commit 08f1eec

Browse files
CaydenLordsCayden Lords
andauthored
docs: add value_to_postgres_default/3 documentation (#791)
Co-authored-by: Cayden Lords <caydenwlords@gmail.com>
1 parent ce8fb09 commit 08f1eec

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

documentation/dsls/DSL-AshPostgres.DataLayer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ end
4242
| [`migrate?`](#postgres-migrate?){: #postgres-migrate? } | `boolean` | `true` | Whether or not to include this resource in the generated migrations with `mix ash.generate_migrations` |
4343
| [`storage_types`](#postgres-storage_types){: #postgres-storage_types } | `keyword` | `[]` | A keyword list of attribute names to the ecto type that should be used for that attribute. Only necessary if you need to override the defaults. |
4444
| [`migration_types`](#postgres-migration_types){: #postgres-migration_types } | `keyword` | `[]` | A keyword list of attribute names to the ecto migration type that should be used for that attribute. Only necessary if you need to override the defaults. |
45-
| [`migration_defaults`](#postgres-migration_defaults){: #postgres-migration_defaults } | `keyword` | `[]` | A keyword list of attribute names to the ecto migration default that should be used for that attribute. The string you use will be placed verbatim in the migration. Use fragments like `fragment(\\"now()\\")`, or for `nil`, use `\\"nil\\"`. |
45+
| [`migration_defaults`](#postgres-migration_defaults){: #postgres-migration_defaults } | `keyword` | `[]` | A keyword list of attribute names to the ecto migration default that should be used for that attribute. The string you use will be placed verbatim in the migration. Use fragments like `fragment(\\"now()\\")`, or for `nil`, use `\\"nil\\"`. For custom `Ash.Type` modules, see `c:AshPostgres.Type.value_to_postgres_default/3`. |
4646
| [`calculations_to_sql`](#postgres-calculations_to_sql){: #postgres-calculations_to_sql } | `keyword` | | A keyword list of calculations and their SQL representation. Used when creating unique indexes for identities over calculations |
4747
| [`identity_wheres_to_sql`](#postgres-identity_wheres_to_sql){: #postgres-identity_wheres_to_sql } | `keyword` | | A keyword list of identity names and the SQL representation of their `where` clause. See `AshPostgres.DataLayer.Info.identity_wheres_to_sql/1` for more details. |
4848
| [`base_filter_sql`](#postgres-base_filter_sql){: #postgres-base_filter_sql } | `String.t` | | A raw sql version of the base_filter, e.g `representative = true`. Required if trying to create a unique constraint on a resource with a base_filter |

lib/data_layer.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ defmodule AshPostgres.DataLayer do
308308
type: :keyword_list,
309309
default: [],
310310
doc: """
311-
A keyword list of attribute names to the ecto migration default that should be used for that attribute. The string you use will be placed verbatim in the migration. Use fragments like `fragment(\\\\"now()\\\\")`, or for `nil`, use `\\\\"nil\\\\"`.
311+
A keyword list of attribute names to the ecto migration default that should be used for that attribute. The string you use will be placed verbatim in the migration. Use fragments like `fragment(\\\\"now()\\\\")`, or for `nil`, use `\\\\"nil\\\\"`. For custom `Ash.Type` modules, see `c:AshPostgres.Type.value_to_postgres_default/3`.
312312
"""
313313
],
314314
calculations_to_sql: [

lib/type.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
defmodule AshPostgres.Type do
66
@moduledoc """
7-
Postgres specific callbacks for `Ash.Type`.
7+
Postgres-specific callbacks for `Ash.Type`.
88
99
Use this in addition to `Ash.Type`.
1010
"""
1111

12+
@doc """
13+
Return the text that will be placed into a migration as an attribute default.
14+
15+
The returned string is placed verbatim into generated migrations.
16+
17+
If this callback is not implemented, the migration generator falls back to
18+
`EctoMigrationDefault`.
19+
"""
1220
@callback value_to_postgres_default(Ash.Type.t(), Ash.Type.constraints(), term) ::
1321
{:ok, String.t()} | :error
1422

0 commit comments

Comments
 (0)