# 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
Name | Type | Default | Docs | |
---|---|---|---|---|
repo * |
module | (any, any -> any)
|
The repo that will be used to fetch your data. See the `AshPostgres.Repo` documentation for more. Can also be a function that takes a resource and a type `:read | :mutate` and returns the repo | ||
migrate? |
boolean
|
true
|
Whether or not to include this resource in the generated migrations with `mix ash.generate_migrations` | |
migration_types |
Keyword.t
|
[]
|
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. | |
migration_defaults |
Keyword.t
|
[]
|
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\\"`. | |
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 | ||
simple_join_first_aggregates |
list(atom)
|
[]
|
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. | |
skip_unique_indexes |
atom | list(atom)
|
false
|
Skip generating unique indexes when generating migrations | |
unique_index_names |
list({list(atom), String.t} | {list(atom), String.t, String.t})
|
[]
|
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"}` | |
exclusion_constraint_names |
`any`
|
[]
|
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"}` | |
identity_index_names |
`any`
|
[]
|
A keyword list of identity names to the unique index name that they should use when being managed by the migration generator. | |
foreign_key_names |
list({atom | String.t, String.t} | {atom | String.t, String.t, String.t})
|
[]
|
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"}` | |
migration_ignore_attributes |
list(atom)
|
[]
|
A list of attributes that will be ignored when generating migrations. | |
table |
String.t
|
The table to store and read the resource from. If this is changed, the migration generator will not remove the old table. | ||
schema |
String.t
|
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. | ||
polymorphic? |
boolean
|
false
|
Declares this resource as polymorphic. See the [polymorphic resources guide](/documentation/topics/polymorphic_resources.md) for more. |
Name | Type | Default | Docs | |
---|---|---|---|---|
fields |
atom | String.t | list(atom | String.t)
|
The fields to include in the index. |
Name | Type | Default | Docs | |
---|---|---|---|---|
name |
String.t
|
the name of the index. Defaults to "#{table}_#{column}_index". | ||
unique |
boolean
|
false
|
indicates whether the index should be unique. | |
concurrently |
boolean
|
false
|
indicates whether the index should be created/dropped concurrently. | |
using |
String.t
|
configures the index type. | ||
prefix |
String.t
|
specify an optional prefix for the index. | ||
where |
String.t
|
specify conditions for a partial index. | ||
message |
String.t
|
A custom message to use for unique indexes that have been violated | ||
include |
list(String.t)
|
specify fields for a covering index. This is not supported by all databases. For more information on PostgreSQL support, please read the official docs. |
Name | Type | Default | Docs | |
---|---|---|---|---|
name * |
atom
|
The name of the statement, must be unique within the resource |
Name | Type | Default | Docs | |
---|---|---|---|---|
up * |
String.t
|
How to create the structure of the statement | ||
down * |
String.t
|
How to tear down the structure of the statement | ||
code? |
boolean
|
false
|
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 |
Name | Type | Default | Docs | |
---|---|---|---|---|
template * |
String.t | atom | list(String.t | atom)
|
A template that will cause the resource to create/manage the specified schema. | ||
create? |
boolean
|
true
|
Whether or not to automatically create a tenant when a record is created | |
update? |
boolean
|
true
|
Whether or not to automatically update the tenant name if the record is udpated |
Name | Type | Default | Docs | |
---|---|---|---|---|
polymorphic_on_delete |
:delete | :nilify | :nothing | :restrict
|
For polymorphic resources, configures the on_delete behavior of the automatically generated foreign keys to source tables. | ||
polymorphic_on_update |
:update | :nilify | :nothing | :restrict
|
For polymorphic resources, configures the on_update behavior of the automatically generated foreign keys to source tables. | ||
polymorphic_name |
:update | :nilify | :nothing | :restrict
|
For polymorphic resources, configures the on_update behavior of the automatically generated foreign keys to source tables. |
Name | Type | Default | Docs | |
---|---|---|---|---|
relationship * |
atom
|
The relationship to be configured |
Name | Type | Default | Docs | |||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ignore? |
boolean
|
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 | ||||||||||||||||||||||||||||||||||||||||||
on_delete |
:delete | :nilify | :nothing | :restrict
|
What should happen to records of this resource when the referenced record of the *destination* resource is deleted. | ||||||||||||||||||||||||||||||||||||||||||
on_update |
:update | :nilify | :nothing | :restrict
|
What should happen to records of this resource when the referenced destination_attribute of the *destination* record is update. | ||||||||||||||||||||||||||||||||||||||||||
deferrable |
false | true | :initially
|
false
|
Wether or not the constraint is deferrable. This only affects the migration generator. | |||||||||||||||||||||||||||||||||||||||||
name |
String.t
|
The name of the foreign key to generate in the database. Defaults to
|