routing

package
v0.0.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

README

Message Routing

Table routing allows you to map source tables and columns to different destinations while preserving data types.

Configuration

Create a YAML file (e.g., routing.yaml) with your routing rules:

users:
  source_table: users
  destination_table: customers
  column_mappings:
    - source: id
      destination: customer_id
    - source: username
      destination: customer_name
  operations:
    - INSERT
    - UPDATE

orders:
  source_table: orders
  destination_table: transactions
  column_mappings:
    - source: id
      destination: transaction_id
    - source: total_amount
      destination: amount
  operations:
    - INSERT
    - UPDATE
    - DELETE

Usage with Routing

Start the worker with the routing configuration:

pg_flo worker postgres --routing-config routing.yaml ...

Routing Rules

Each table configuration supports:

  • source_table: Original table name (required)
  • destination_table: Target table name (optional, defaults to source_table)
  • column_mappings: List of column name mappings (optional)
    • source: Original column name
    • destination: New column name in target
  • operations: List of operations to replicate (required)
    • Supported: INSERT, UPDATE, DELETE

Important Notes

  • Column data types must match between source and destination
  • Primary keys are automatically mapped
  • All specified columns must exist in both tables
  • Operations not listed in operations will be ignored. Defaults to all operations.
  • Unlisted columns are preserved with their original names
  • Complex types (jsonb, arrays) are preserved during mapping

Examples

Basic Table Mapping
users:
  source_table: users
  destination_table: customers
  operations:
    - INSERT
    - UPDATE
Column Remapping
products:
  source_table: products
  destination_table: items
  column_mappings:
    - source: id
      destination: item_id
    - source: name
      destination: item_name
  operations:
    - INSERT
    - UPDATE
    - DELETE

Documentation

Overview

Package routing provides message routing capabilities for pg_flo.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsOperation

func ContainsOperation(operations []utils.OperationType, operation utils.OperationType) bool

ContainsOperation checks if the given operation is in the list of operations

func GetMappedColumnName

func GetMappedColumnName(mappings []ColumnMapping, sourceName string) string

GetMappedColumnName returns the destination column name for a given source column name

Types

type ColumnMapping

type ColumnMapping struct {
	Source      string `yaml:"source"`
	Destination string `yaml:"destination"`
}

ColumnMapping defines how columns are mapped between source and destination

type Router

type Router struct {
	Routes map[string]TableRoute
	// contains filtered or unexported fields
}

Router manages message routing and transformation

func NewRouter

func NewRouter() *Router

NewRouter creates a new Router instance

func (*Router) AddRoute

func (r *Router) AddRoute(route TableRoute)

AddRoute adds a new table route to the router

func (*Router) ApplyRouting

func (r *Router) ApplyRouting(message *utils.CDCMessage) (*utils.CDCMessage, error)

ApplyRouting applies routing rules to transform a CDC message

func (*Router) LoadRoutes

func (r *Router) LoadRoutes(config map[string]TableRoute) error

LoadRoutes loads routes from the provided configuration

type TableRoute

type TableRoute struct {
	SourceTable      string                `yaml:"source_table"`
	DestinationTable string                `yaml:"destination_table"`
	ColumnMappings   []ColumnMapping       `yaml:"column_mappings"`
	Operations       []utils.OperationType `yaml:"operations"`
}

TableRoute defines routing configuration for a specific table

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL