Migrate from deprecated substreams-sink to integrated substreams/sink package#129
Migrate from deprecated substreams-sink to integrated substreams/sink package#129
Conversation
- Update all imports from github.com/streamingfast/substreams-sink to github.com/streamingfast/substreams/sink - Update NewFromViper calls to use new signature (removed endpoint and blockRange params, added userAgent) - Replace BlockRange() method calls with StartBlock() and StopBlock() - Update flag management to use FlagIgnore (deprecated but compatible API) - Remove sink.RegisterMetrics() calls as they're no longer in the API - Update readBlockRangeArgument to use bstream.ParseRange - Update ReadManifestAndModuleAndBlockRange to ReadManifestAndModule - Remove unused imports Co-authored-by: maoueh <123014+maoueh@users.noreply.github.com>
- Exclude endpoint, start-block, and stop-block flags from sink library - Remove shorthand from substreams-endpoint to avoid conflict with sink's endpoint flag - This allows from_proto to manage its own endpoint and block range flags Co-authored-by: maoueh <123014+maoueh@users.noreply.github.com>
Address code review feedback by adding proper error checking when setting flags programmatically Co-authored-by: maoueh <123014+maoueh@users.noreply.github.com>
| manifestPath, | ||
| outputModuleName, | ||
| blockRange, | ||
| "substreams-sink-sql/1.0.0", |
There was a problem hiding this comment.
We can probably pull the version from the main CLI directly somehow.
There was a problem hiding this comment.
Updated to use the version variable from main.go (commit 690d940). Now uses fmt.Sprintf("substreams-sink-sql/%s", version) which will be populated via ldflags at build time.
cmd/substreams-sink-sql/run.go
Outdated
|
|
||
| var sinkRunCmd = Command(sinkRunE, | ||
| "run <dsn> <manifest> [<start>:<stop>]", | ||
| "run <dsn> <manifest> [<module>]", |
There was a problem hiding this comment.
Could we remain compatible with previous CLI way, I would like to avoid a breaking change for users.
There was a problem hiding this comment.
Backward compatibility restored (commit 690d940). The run command now accepts [<start>:<stop>] block range as before. The code detects if the third argument contains ':' to determine if it's a block range and parses it accordingly, maintaining the original CLI behavior.
| Name: "dummy", | ||
| InitialBlock: 0, | ||
| }, in) | ||
| return bstream.ParseRange(in) |
There was a problem hiding this comment.
Is this equivalent to previous code?
There was a problem hiding this comment.
Yes, it's equivalent (commit 690d940). Added a comment explaining that bstream.ParseRange handles the same block range format that the old sink.ReadBlockRange did (e.g., "100:200", "100:", ":200"). The only difference is the API surface changed but the parsing behavior remains the same.
| } | ||
| } | ||
|
|
||
| // Set the endpoint flag for the sink to use |
There was a problem hiding this comment.
It would be better for all those funky cmd.Flags().Set(...) call to comment that this is to bridge with substreams/sink library to it can work properly.
Adjust for such all changes in the PR.
There was a problem hiding this comment.
Added explanatory comments for all flag bridging code (commit 690d940). Comments now clarify that these cmd.Flags().Set() calls bridge custom flags with the substreams/sink library's expected flags.
- Use version variable from main CLI instead of hardcoded string (addresses comment 2819648900) - Restore backward compatibility for run command - accept [<start>:<stop>] block range argument (addresses comment 2819653763) - Add comments explaining flag bridging with substreams/sink library (addresses comment 2819662071) - Add comment explaining readBlockRangeArgument equivalence (addresses comment 2819655754) Co-authored-by: maoueh <123014+maoueh@users.noreply.github.com>
The repository was using the deprecated standalone
github.com/streamingfast/substreams-sinklibrary. This migrates to the integratedgithub.com/streamingfast/substreams/sinkpackage per the migration guide.Changes
API Signature Updates
endpointandblockRangeparameters (now handled via flags), addeduserAgentparameter (dynamically uses version from main CLI)StartBlock()andStopBlock()methodsReadManifestAndModuleFlag Management
--start-blockand--stop-blockflags--endpointflag with automatic network inference from manifestFlagIgnoreAPI for minimal migration impactfrom-protocommand by excluding overlapping sink flagsBackward Compatibility
runcommand continues to accept the original[<start>:<stop>]block range syntax as a positional argumentExample
Migration Approach
Minimal migration path using deprecated but compatible APIs to reduce surface area of changes while maintaining full backward compatibility with existing CLI usage patterns.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.