Skip to content

Commit

Permalink
document that csv gen/inject are postgresql-only, add validation of dsn
Browse files Browse the repository at this point in the history
  • Loading branch information
sduchesneau committed Dec 19, 2023
1 parent ddac2da commit 4aa45a1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/substreams-sink-sql/generate_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const lastCursorFilename = "last_cursor"

var generateCsvCmd = Command(generateCsvE,
"generate-csv <dsn> <manifest> [start]:<stop>",
"Generates CSVs for each table so it can be bulk inserted with `inject-csv`",
"Generates CSVs for each table so it can be bulk inserted with `inject-csv` (for postgresql only)",
Description(`
This command command is the first of a multi-step process to bulk insert data into an SQL database.
This command command is the first of a multi-step process to bulk insert data into a PostgreSQL database.
It creates a folder for each table and generates CSVs for block ranges. This files can be used with
the 'inject-csv' command to bulk insert data into the database.
Expand Down
6 changes: 5 additions & 1 deletion cmd/substreams-sink-sql/inject_csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

var injectCSVCmd = Command(injectCSVE,
"inject-csv <psql_dsn> <input_path> <table> <start>:<stop>",
"Injects generated CSV rows for <table> into the database pointed by <psql_dsn> argument.",
"Injects generated CSV rows for <table> into the database pointed by <psql_dsn> argument. (postgresql-only)",
Description(`
Can be run in parallel for multiple rows up to the same <stop>, the <start> and <stop> block must be provided explicitely.
Expand All @@ -49,6 +49,10 @@ func injectCSVE(cmd *cobra.Command, args []string) error {
return fmt.Errorf("invalid sql DSN %q: %w", psqlDSN, err)
}

if sqlDSN.Driver() != "postgres" {
return fmt.Errorf("inject-csv only supports postgresql DSNs, got %q", sqlDSN.Driver())
}

zlog.Info("connecting to input store")
inputStore, err := dstore.NewStore(inputPath, "csv", "", false)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions db/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func ParseDSN(dsn string) (*DSN, error) {
return d, nil
}

func (c *DSN) Driver() string {
return c.driver
}

func (c *DSN) ConnString() string {
if c.driver == "clickhouse" {
return c.original
Expand Down

0 comments on commit 4aa45a1

Please sign in to comment.