[surrealdb]
url = "http://localhost:8000"
username = "root"
password = "changeme"    # OVERSYNC_SURREALDB_PASS
namespace = "oversync"
database = "sync"

[[sinks]]
name = "stdout"
type = "stdout"

[sinks.config]
pretty = true

[[sinks]]
name = "kafka-main"
type = "kafka"

[sinks.config]
brokers = "localhost:9092"
topic = "sync-events"

[[pipes]]
name = "product_a"
targets = ["stdout"]

[pipes.origin]
connector = "postgres"
dsn = "postgres://readonly@localhost:5432/metadata"

[pipes.schedule]
interval_secs = 300       # 5 minutes

[pipes.delta]
fail_safe_threshold = 30.0

[[pipes.queries]]
id = "tables"
sql = """
SELECT
  oid::text AS oid,
  relname AS table_name,
  relkind::text AS kind
FROM pg_class
WHERE relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = 'public')
"""
key_column = "oid"

[[pipes.queries]]
id = "columns"
sql = """
SELECT
  (attrelid::text || '.' || attnum::text) AS id,
  attrelid::text AS table_oid,
  attname AS column_name,
  format_type(atttypid, atttypmod) AS data_type
FROM pg_attribute
WHERE attnum > 0 AND NOT attisdropped
"""
key_column = "id"

# Recipe-based onboarding:
#
# [[pipes]]
# name = "catalog-public"
# targets = ["kafka-main"]
#
# [pipes.origin]
# connector = "postgres"
# dsn = "postgres://placeholder"
# credential = "catalog-postgres"
#
# [pipes.schedule]
# interval_secs = 900
#
# [pipes.delta]
# diff_mode = "db"
#
# [pipes.recipe]
# type = "postgres_metadata"
# prefix = "catalog"
# schemas = ["public"]
#
# Saved recipe template:
#
# [[pipe_presets]]
# name = "postgres-snapshot-template"
# description = "Reusable PostgreSQL onboarding template"
#
# [pipe_presets.spec.origin]
# connector = "postgres"
# dsn = "postgres://placeholder"
# credential = "{{credential_name}}"
#
# [[pipe_presets.spec.parameters]]
# name = "credential_name"
# label = "Credential"
# required = true
# secret = false
#
# [[pipe_presets.spec.parameters]]
# name = "source_name"
# label = "Source name"
# required = true
# secret = false
#
# [pipe_presets.spec.schedule]
# interval_secs = 300
#
# [pipe_presets.spec.delta]
# diff_mode = "db"
#
# [pipe_presets.spec.recipe]
# type = "postgres_snapshot"
# prefix = "{{source_name}}"
# schemas = ["public"]
