View Source Electric.Shapes.Partitions (electric v1.0.1)

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.

Summary

Functions

Update the partition information table with the given shape.

Handle events from the replication stream, updating the partition mapping or expanding changes to partitions into the partition root as appropriate.

Utility function to update the partition map with the given relation.

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

Types

@type options() :: [{:inspector, Electric.Postgres.Inspector.inspector()}]
@type partition_table() :: Electric.relation()
@type root_table() :: Electric.relation()
@type shape_id() :: term()
@type t() :: %Electric.Shapes.Partitions{
  active: non_neg_integer(),
  inspector: Electric.Postgres.Inspector.inspector(),
  partition_ownership: %{required(Electric.relation()) => MapSet.t(shape_id())},
  partitions: %{required(partition_table()) => root_table()}
}

Functions

Link to this function

add_shape(state, shape_id, shape)

View Source
@spec add_shape(t(), shape_id(), Electric.Shapes.Shape.t()) :: t()

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.

Link to this function

handle_event(state, relation)

View Source

Handle events from the replication stream, updating the partition mapping or expanding changes to partitions into the partition root as appropriate.

Link to this function

handle_relation(state, relation)

View Source
@spec handle_relation(t(), Electric.Replication.Changes.Relation.t()) :: t()

Utility function to update the partition map with the given relation.

@spec new(options()) :: t()
Link to this function

remove_shape(state, shape_id)

View Source
@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.