<!--
This file was generated by Spark. Do not edit it by hand.
-->
# AshPostgresPartition

Ash Postgres Partition is an extension for Ash Resources
It makes it easier to add partitions and to manage them
It also supports having tenants


## partition
Example of how to use this to add a `:list` type partition to a resource
```elixir
  defmodule MyResource do
    use Ash.Resource,
      domain: MyDomain,
      data_layer: AshPostgres.DataLayer,
      extensions: [AshPostgresPartition]

    attributes do
      uuid_v7_primary_key(:id)

      attribute(:key, :string, primary_key?: true, allow_nil?: false)
      attribute(:data, :string)

      update_timestamp(:updated_at, writable?: true)
      create_timestamp(:inserted_at, writable?: true)
    end

    postgres do
      table("mytable")
      repo(MyRepo)
    end

    actions do
      defaults([:create, :read])
      default_accept([:key, :data])
    end

    partition do
      type(:list)
      attribute(:key)
      name fn table, key -> {:ok, table <> "_" <> key} end
    end

    multitenancy do
      strategy(:context)
    end
  end
```







### Options

| Name | Type | Default | Docs |
|------|------|---------|------|
| [`type`](#partition-type){: #partition-type .spark-required} | `:range \| :list \| :hash` |  | Type of partitioning to use, possible values are `:range`, `:list` and `:hash` |
| [`attribute`](#partition-attribute){: #partition-attribute .spark-required} | `atom` |  | What attribute to use for partitioning |
| [`name`](#partition-name){: #partition-name .spark-required} | `(any, any -> any)` |  | Function to generate the name of the partition, expects {:ok, binary()}, the function is provided the table name and the key |
| [`generate_default_partition?`](#partition-generate_default_partition?){: #partition-generate_default_partition? } | `boolean` | `false` | For `:range` and `:list` types, adds a `DEFAULT` partition named `<table>_default` for rows not fitting into any other partition. The partition is created by the migrations generated with `mix ash_postgres.generate_migrations`. Note that creating a new partition fails if the default partition already holds rows belonging to it. |
| [`opts`](#partition-opts){: #partition-opts } | `keyword` | `[]` | When using `:hash` type, you must provide a `:count` option with number of partitions to create |







<style type="text/css">.spark-required::after { content: "*"; color: red !important; }</style>
