ash_postgres/documentation/dsls/DSL:-AshPostgres.DataLayer.cheatmd
2023-09-26 23:17:47 -04:00

1302 lines
30 KiB
Text

<!--
This file was generated by Spark. Do not edit it by hand.
-->
# DSL: AshPostgres.DataLayer
A postgres data layer that leverages Ecto's postgres capabilities.
## postgres
Postgres data layer configuration
### Nested DSLs
* [custom_indexes](#postgres-custom_indexes)
* index
* [custom_statements](#postgres-custom_statements)
* statement
* [manage_tenant](#postgres-manage_tenant)
* [references](#postgres-references)
* reference
* [check_constraints](#postgres-check_constraints)
* check_constraint
### Examples
```
postgres do
repo MyApp.Repo
table "organizations"
end
```
### Options
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th colspan=2>Docs</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
<a id="postgres-repo" href="#postgres-repo">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
repo
</span>
</a>
<sup style="color: red">*</sup>
</td>
<td style="text-align: left">
<code class="inline">atom</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The repo that will be used to fetch your data. See the `AshPostgres.Repo` documentation for more
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-migrate?" href="#postgres-migrate?">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
migrate?
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">boolean</code>
</td>
<td style="text-align: left">
<code class="inline">true</code>
</td>
<td style="text-align: left" colspan=2>
Whether or not to include this resource in the generated migrations with `mix ash.generate_migrations`
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-migration_types" href="#postgres-migration_types">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
migration_types
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">Keyword.t</code>
</td>
<td style="text-align: left">
<code class="inline">[]</code>
</td>
<td style="text-align: left" colspan=2>
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.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-migration_defaults" href="#postgres-migration_defaults">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
migration_defaults
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">Keyword.t</code>
</td>
<td style="text-align: left">
<code class="inline">[]</code>
</td>
<td style="text-align: left" colspan=2>
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\\"`.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-base_filter_sql" href="#postgres-base_filter_sql">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
base_filter_sql
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
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
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-simple_join_first_aggregates" href="#postgres-simple_join_first_aggregates">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
simple_join_first_aggregates
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">list(atom)</code>
</td>
<td style="text-align: left">
<code class="inline">[]</code>
</td>
<td style="text-align: left" colspan=2>
A list of `:first` type aggregate names that can be joined to using a simple join. Use when you have a `:first` aggregate that uses a to-many relationship , but your `filter` statement ensures that there is only one result. Optimizes the generated query.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-skip_unique_indexes" href="#postgres-skip_unique_indexes">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
skip_unique_indexes
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">list(atom) | atom</code>
</td>
<td style="text-align: left">
<code class="inline">false</code>
</td>
<td style="text-align: left" colspan=2>
Skip generating unique indexes when generating migrations
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-unique_index_names" href="#postgres-unique_index_names">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
unique_index_names
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">list({list(atom), String.t} | {list(atom), String.t, String.t})</code>
</td>
<td style="text-align: left">
<code class="inline">[]</code>
</td>
<td style="text-align: left" colspan=2>
A list of unique index names that could raise errors that are not configured in identities, or an mfa to a function that takes a changeset and returns the list. In the format `{[:affected, :keys], "name_of_constraint"}` or `{[:affected, :keys], "name_of_constraint", "custom error message"}`
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-exclusion_constraint_names" href="#postgres-exclusion_constraint_names">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
exclusion_constraint_names
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">`any`</code>
</td>
<td style="text-align: left">
<code class="inline">[]</code>
</td>
<td style="text-align: left" colspan=2>
A list of exclusion constraint names that could raise errors. Must be in the format `{:affected_key, "name_of_constraint"}` or `{:affected_key, "name_of_constraint", "custom error message"}`
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-identity_index_names" href="#postgres-identity_index_names">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
identity_index_names
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">`any`</code>
</td>
<td style="text-align: left">
<code class="inline">[]</code>
</td>
<td style="text-align: left" colspan=2>
A keyword list of identity names to the unique index name that they should use when being managed by the migration generator.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-foreign_key_names" href="#postgres-foreign_key_names">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
foreign_key_names
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">list({atom, String.t} | {String.t, String.t})</code>
</td>
<td style="text-align: left">
<code class="inline">[]</code>
</td>
<td style="text-align: left" colspan=2>
A list of foreign keys that could raise errors, or an mfa to a function that takes a changeset and returns a list. In the format: `{:key, "name_of_constraint"}` or `{:key, "name_of_constraint", "custom error message"}`
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-migration_ignore_attributes" href="#postgres-migration_ignore_attributes">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
migration_ignore_attributes
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">list(atom)</code>
</td>
<td style="text-align: left">
<code class="inline">[]</code>
</td>
<td style="text-align: left" colspan=2>
A list of attributes that will be ignored when generating migrations.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-table" href="#postgres-table">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
table
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The table to store and read the resource from. If this is changed, the migration generator will not remove the old table.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-schema" href="#postgres-schema">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
schema
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The schema that the table is located in. Schema-based multitenancy will supercede this option. If this is changed, the migration generator will not remove the old schema.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-polymorphic?" href="#postgres-polymorphic?">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
polymorphic?
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">boolean</code>
</td>
<td style="text-align: left">
<code class="inline">false</code>
</td>
<td style="text-align: left" colspan=2>
Declares this resource as polymorphic. See the [polymorphic resources guide](/documentation/topics/polymorphic_resources.md) for more.
</td>
</tr>
</tbody>
</table>
## postgres.custom_indexes
A section for configuring indexes to be created by the migration generator.
In general, prefer to use `identities` for simple unique constraints. This is a tool to allow
for declaring more complex indexes.
### Nested DSLs
* [index](#postgres-custom_indexes-index)
### Examples
```
custom_indexes do
index [:column1, :column2], unique: true, where: "thing = TRUE"
end
```
## postgres.custom_indexes.index
```elixir
index fields
```
Add an index to be managed by the migration generator.
### Examples
```
index ["column", "column2"], unique: true, where: "thing = TRUE"
```
### Options
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th colspan=2>Docs</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
<a id="fields-fields" href="#fields-fields">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
fields
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">list(atom | String.t) | atom | String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The fields to include in the index.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="fields-name" href="#fields-name">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
name
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
the name of the index. Defaults to "#{table}_#{column}_index".
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="fields-unique" href="#fields-unique">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
unique
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">boolean</code>
</td>
<td style="text-align: left">
<code class="inline">false</code>
</td>
<td style="text-align: left" colspan=2>
indicates whether the index should be unique.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="fields-concurrently" href="#fields-concurrently">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
concurrently
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">boolean</code>
</td>
<td style="text-align: left">
<code class="inline">false</code>
</td>
<td style="text-align: left" colspan=2>
indicates whether the index should be created/dropped concurrently.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="fields-using" href="#fields-using">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
using
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
configures the index type.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="fields-prefix" href="#fields-prefix">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
prefix
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
specify an optional prefix for the index.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="fields-where" href="#fields-where">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
where
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
specify conditions for a partial index.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="fields-message" href="#fields-message">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
message
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
A custom message to use for unique indexes that have been violated
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="fields-include" href="#fields-include">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
include
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">list(String.t)</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
specify fields for a covering index. This is not supported by all databases. For more information on PostgreSQL support, please read the official docs.
</td>
</tr>
</tbody>
</table>
### Introspection
Target: `AshPostgres.CustomIndex`
## postgres.custom_statements
A section for configuring custom statements to be added to migrations.
Changing custom statements may require manual intervention, because Ash can't determine what order they should run
in (i.e if they depend on table structure that you've added, or vice versa). As such, any `down` statements we run
for custom statements happen first, and any `up` statements happen last.
Additionally, when changing a custom statement, we must make some assumptions, i.e that we should migrate
the old structure down using the previously configured `down` and recreate it.
This may not be desired, and so what you may end up doing is simply modifying the old migration and deleting whatever was
generated by the migration generator. As always: read your migrations after generating them!
### Nested DSLs
* [statement](#postgres-custom_statements-statement)
### Examples
```
custom_statements do
# the name is used to detect if you remove or modify the statement
statement :pgweb_idx do
up "CREATE INDEX pgweb_idx ON pgweb USING GIN (to_tsvector('english', title || ' ' || body));"
down "DROP INDEX pgweb_idx;"
end
end
```
## postgres.custom_statements.statement
```elixir
statement name
```
Add a custom statement for migrations.
### Examples
```
statement :pgweb_idx do
up "CREATE INDEX pgweb_idx ON pgweb USING GIN (to_tsvector('english', title || ' ' || body));"
down "DROP INDEX pgweb_idx;"
end
```
### Options
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th colspan=2>Docs</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
<a id="name-name" href="#name-name">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
name
</span>
</a>
<sup style="color: red">*</sup>
</td>
<td style="text-align: left">
<code class="inline">atom</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The name of the statement, must be unique within the resource
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="name-up" href="#name-up">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
up
</span>
</a>
<sup style="color: red">*</sup>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
How to create the structure of the statement
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="name-down" href="#name-down">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
down
</span>
</a>
<sup style="color: red">*</sup>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
How to tear down the structure of the statement
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="name-code?" href="#name-code?">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
code?
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">boolean</code>
</td>
<td style="text-align: left">
<code class="inline">false</code>
</td>
<td style="text-align: left" colspan=2>
By default, we place the strings inside of ecto migration's `execute/1` function and assume they are sql. Use this option if you want to provide custom elixir code to be placed directly in the migrations
</td>
</tr>
</tbody>
</table>
### Introspection
Target: `AshPostgres.Statement`
## postgres.manage_tenant
Configuration for the behavior of a resource that manages a tenant
### Examples
```
manage_tenant do
template ["organization_", :id]
create? true
update? false
end
```
### Options
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th colspan=2>Docs</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
<a id="postgres-manage_tenant-template" href="#postgres-manage_tenant-template">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
template
</span>
</a>
<sup style="color: red">*</sup>
</td>
<td style="text-align: left">
<code class="inline">list(String.t | atom) | String.t | atom</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
A template that will cause the resource to create/manage the specified schema.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-manage_tenant-create?" href="#postgres-manage_tenant-create?">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
create?
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">boolean</code>
</td>
<td style="text-align: left">
<code class="inline">true</code>
</td>
<td style="text-align: left" colspan=2>
Whether or not to automatically create a tenant when a record is created
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-manage_tenant-update?" href="#postgres-manage_tenant-update?">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
update?
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">boolean</code>
</td>
<td style="text-align: left">
<code class="inline">true</code>
</td>
<td style="text-align: left" colspan=2>
Whether or not to automatically update the tenant name if the record is udpated
</td>
</tr>
</tbody>
</table>
## postgres.references
A section for configuring the references (foreign keys) in resource migrations.
This section is only relevant if you are using the migration generator with this resource.
Otherwise, it has no effect.
### Nested DSLs
* [reference](#postgres-references-reference)
### Examples
```
references do
reference :post, on_delete: :delete, on_update: :update, name: "comments_to_posts_fkey"
end
```
### Options
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th colspan=2>Docs</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
<a id="postgres-references-polymorphic_on_delete" href="#postgres-references-polymorphic_on_delete">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
polymorphic_on_delete
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">:delete | :nilify | :nothing | :restrict</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
For polymorphic resources, configures the on_delete behavior of the automatically generated foreign keys to source tables.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-references-polymorphic_on_update" href="#postgres-references-polymorphic_on_update">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
polymorphic_on_update
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">:update | :nilify | :nothing | :restrict</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
For polymorphic resources, configures the on_update behavior of the automatically generated foreign keys to source tables.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="postgres-references-polymorphic_name" href="#postgres-references-polymorphic_name">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
polymorphic_name
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">:update | :nilify | :nothing | :restrict</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
For polymorphic resources, configures the on_update behavior of the automatically generated foreign keys to source tables.
</td>
</tr>
</tbody>
</table>
## postgres.references.reference
```elixir
reference relationship
```
Configures the reference for a relationship in resource migrations.
Keep in mind that multiple relationships can theoretically involve the same destination and foreign keys.
In those cases, you only need to configure the `reference` behavior for one of them. Any conflicts will result
in an error, across this resource and any other resources that share a table with this one. For this reason,
instead of adding a reference configuration for `:nothing`, its best to just leave the configuration out, as that
is the default behavior if *no* relationship anywhere has configured the behavior of that reference.
### Examples
```
reference :post, on_delete: :delete, on_update: :update, name: "comments_to_posts_fkey"
```
### Options
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th colspan=2>Docs</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
<a id="relationship-relationship" href="#relationship-relationship">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
relationship
</span>
</a>
<sup style="color: red">*</sup>
</td>
<td style="text-align: left">
<code class="inline">atom</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The relationship to be configured
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="relationship-ignore?" href="#relationship-ignore?">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
ignore?
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">boolean</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
If set to true, no reference is created for the given relationship. This is useful if you need to define it in some custom way
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="relationship-on_delete" href="#relationship-on_delete">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
on_delete
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">:delete | :nilify | :nothing | :restrict</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
What should happen to records of this resource when the referenced record of the *destination* resource is deleted.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="relationship-on_update" href="#relationship-on_update">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
on_update
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">:update | :nilify | :nothing | :restrict</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
What should happen to records of this resource when the referenced destination_attribute of the *destination* record is update.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="relationship-deferrable" href="#relationship-deferrable">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
deferrable
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">false | true | :initially</code>
</td>
<td style="text-align: left">
<code class="inline">false</code>
</td>
<td style="text-align: left" colspan=2>
Wether or not the constraint is deferrable. This only affects the migration generator.
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="relationship-name" href="#relationship-name">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
name
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The name of the foreign key to generate in the database. Defaults to <table>_<source_attribute>_fkey
</td>
</tr>
</tbody>
</table>
### Introspection
Target: `AshPostgres.Reference`
## postgres.check_constraints
A section for configuring the check constraints for a given table.
This can be used to automatically create those check constraints, or just to provide message when they are raised
### Nested DSLs
* [check_constraint](#postgres-check_constraints-check_constraint)
### Examples
```
check_constraints do
check_constraint :price, "price_must_be_positive", check: "price > 0", message: "price must be positive"
end
```
## postgres.check_constraints.check_constraint
```elixir
check_constraint attribute, name
```
Add a check constraint to be validated.
If a check constraint exists on the table but not in this section, and it produces an error, a runtime error will be raised.
Provide a list of attributes instead of a single attribute to add the message to multiple attributes.
By adding the `check` option, the migration generator will include it when generating migrations.
### Examples
```
check_constraint :price, "price_must_be_positive", check: "price > 0", message: "price must be positive"
```
### Options
<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th colspan=2>Docs</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left">
<a id="attribute-name-attribute" href="#attribute-name-attribute">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
attribute
</span>
</a>
<sup style="color: red">*</sup>
</td>
<td style="text-align: left">
<code class="inline">`any`</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The attribute or list of attributes to which an error will be added if the check constraint fails
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="attribute-name-name" href="#attribute-name-name">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
name
</span>
</a>
<sup style="color: red">*</sup>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The name of the constraint
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="attribute-name-message" href="#attribute-name-message">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
message
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The message to be added if the check constraint fails
</td>
</tr>
<tr>
<td style="text-align: left">
<a id="attribute-name-check" href="#attribute-name-check">
<span style="font-family: Inconsolata, Menlo, Courier, monospace;">
check
</span>
</a>
</td>
<td style="text-align: left">
<code class="inline">String.t</code>
</td>
<td style="text-align: left">
</td>
<td style="text-align: left" colspan=2>
The contents of the check. If this is set, the migration generator will include it when generating migrations
</td>
</tr>
</tbody>
</table>
### Introspection
Target: `AshPostgres.CheckConstraint`