# `Electric.Shapes.Partitions`
[🔗](https://github.com/electric-sql/electric/tree/%40core/sync-service%401.6.2/packages/sync-service/lib/electric/shapes/partitions.ex#L1)

Keeps track of shapes defined on partitioned tables and re-writes
transactions to send an equivalent change on the root partitioned table for
every change to a partition of that table.

# `options`

```elixir
@type options() :: [{:inspector, Electric.Postgres.Inspector.inspector()}]
```

# `partition_table`

```elixir
@type partition_table() :: Electric.relation()
```

# `root_table`

```elixir
@type root_table() :: Electric.relation()
```

# `shape_id`

```elixir
@type shape_id() :: term()
```

# `t`

```elixir
@type t() :: %Electric.Shapes.Partitions{
  active: non_neg_integer(),
  inspector: Electric.Postgres.Inspector.inspector(),
  partition_ownership: %{required(Electric.relation()) =&gt; MapSet.t(shape_id())},
  partitions: %{required(partition_table()) =&gt; root_table()}
}
```

# `add_shape`

```elixir
@spec add_shape(t(), shape_id(), Electric.Shapes.Shape.t()) ::
  {:ok, t()} | {:error, :connection_not_available}
```

Update the partition information table with the given shape.

If the shape is  defined on a partitioned table (not a partition of that
table) then this will expand the mapping function to add a change to the
partition root for every change to a partition of that root.

# `handle_relation`

```elixir
@spec handle_relation(t(), Electric.Replication.Changes.Relation.t()) ::
  {:ok, t()} | {:error, :connection_not_available}
```

Handle relation changes from the replication stream,
expanding changes to partitions into the partition root as appropriate.

# `handle_txn_fragment`

```elixir
@spec handle_txn_fragment(t(), Electric.Replication.Changes.TransactionFragment.t()) ::
  {t(), Electric.Replication.Changes.TransactionFragment.t()}
```

Handle transaction fragments from the replication stream, updating the partition mapping as appropriate.

# `new`

```elixir
@spec new(options()) :: t()
```

# `remove_shape`

```elixir
@spec remove_shape(t(), shape_id()) :: t()
```

Remove a shape that was previously added under the given id.

If that shape was defined on a partitioned table, this will clean up the
partition mapping table.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
