Skip to content

feat: add substreams sink postgres and substreams sink clickhouse CLI subcommands#761

Open
maoueh wants to merge 80 commits into
developfrom
agents-split-substreams-sink-commands
Open

feat: add substreams sink postgres and substreams sink clickhouse CLI subcommands#761
maoueh wants to merge 80 commits into
developfrom
agents-split-substreams-sink-commands

Conversation

@maoueh
Copy link
Copy Markdown
Contributor

@maoueh maoueh commented May 1, 2026

Summary

Implements two new CLI subcommands:

  • substreams sink postgres — streams data into a PostgreSQL database
  • substreams sink clickhouse — streams data into a ClickHouse database

Both commands support two modes:

  1. DatabaseChanges mode — uses substreams-sink-database-changes proto messages to upsert/delete rows
  2. Proto-based mode — inserts protobuf messages directly, inferring schema from proto descriptors

Changes

New files

  • cmd/substreams/sink_postgres.go — CLI command for Postgres sink
  • cmd/substreams/sink_clickhouse.go — CLI command for ClickHouse sink
  • sink/sql/ — Vendored source packages copied from streamingfast/substreams-sink-sql with import paths rewritten to github.com/streamingfast/substreams/sink/sql/...
    • sink/sql/bytes/ — bytes encoding helpers
    • sink/sql/db_changes/db/ — database loader/dialect (Postgres + ClickHouse)
    • sink/sql/db_changes/bundler/ — file bundler for batch uploads
    • sink/sql/db_changes/sinker/ — sinker implementation using db-changes proto
    • sink/sql/db_proto/ — sinker implementation using proto messages directly
    • sink/sql/pb/ — protobuf generated code for schema/services
    • sink/sql/shared.go — shared service extraction helper

Modified files

  • go.mod / go.sum — added 9 new direct dependencies:
    • github.com/AfterShip/clickhouse-sql-parser v0.4.9
    • github.com/ClickHouse/ch-go v0.68.0
    • github.com/ClickHouse/clickhouse-go/v2 v2.40.3
    • github.com/drone/envsubst v1.0.3
    • github.com/jackc/pgx/v4 v4.18.1
    • github.com/jmoiron/sqlx v1.4.0
    • github.com/lib/pq v1.10.9
    • github.com/streamingfast/substreams-sink-database-changes v1.3.2-0.20260110015235-04b544bbecb9
    • github.com/wk8/go-ordered-map/v2 v2.1.7

Notes

  • substreams-sink-sql cannot be imported as a direct dependency (circular — it imports substreams), so source packages are vendored under sink/sql/ with import paths rewritten
  • ClickHouse sink sets HandleReorgs: false (ClickHouse doesn't support reorgs via history table)
  • Postgres sink sets HandleReorgs: true
  • Uses github.com/mr-tron/base58 (already a transitive dep) instead of btcutil/base58

To sync locally

git pull origin agents-split-substreams-sink-commands

maoueh and others added 30 commits May 1, 2026 03:06
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Fix Quoted() function and push remaining db_changes files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…hema files

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tration in dialect_clickhouse.go)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add FieldInfo and TableInfo functions to db_proto/proto/utils.go
- Create testing.go with TestTx type in db_changes/db/
- Copy database.pb.go locally to avoid external module dependency
- Update sinker.go import to use local pbdatabase package

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…-changes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…dialects and sinker)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tgres dialect)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ck_house and postgres db_proto)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
maoueh and others added 30 commits May 1, 2026 09:35
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…testtx)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ops, user)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tats)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Delete testing.go which redeclares TestTx already defined in testtx.go.
This was incorrectly included by a previous agent and is not needed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The sink/sql/services/ package references proto types not in stub.
These files were incorrectly added and are not needed by the CLI commands.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…pes)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file was incorrectly placed under sink/sql/db_changes/pb/...
The correct location is pb/sf/substreams/sink/database/v1/ which
already has a stub.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file is not referenced by any code in the repository.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant