diff --git a/.gitignore b/.gitignore index 5555cbc..18c5716 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.pgsql/data \ No newline at end of file +.pgsql/data +bin \ No newline at end of file diff --git a/Makefile b/Makefile index 7c68b83..f523b41 100644 --- a/Makefile +++ b/Makefile @@ -15,3 +15,7 @@ is-postgres-running: .PHONY: pgweb pgweb:is-postgres-running @pgweb --url "postgres://test_source@localhost:5432/test_source?sslmode=disable" + + +build: + CGO_ENABLEd=0 go build -o bin/subsetter ${PACKAGE}/cli diff --git a/README.md b/README.md index 5f17498..2e537bc 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,19 @@ Utilizing the native PostgreSQL COPY command, pg-subsetter performs data transfe ## Usage +``` +Usage of subsetter: + -dst string + Destination DSN + -f float + Fraction of rows to copy (default 0.05) + -src string + Source DSN +``` + + +Example: + ```pg-subsetter -src postgresql://:@/bigdb -dst postgresql://:@/littledb -f 0.05``` # Installing diff --git a/cli/main.go b/cli/main.go index 55a25a6..dd07c59 100644 --- a/cli/main.go +++ b/cli/main.go @@ -6,12 +6,20 @@ import ( "github.com/rs/zerolog/log" ) -var src = flag.String("src", "", "Source DSN") -var dst = flag.String("dst", "", "Destination DSN") -var fraction = flag.Float64("f", 1.0, "Fraction of rows to copy") +var src = flag.String("src", "", "Source database DSN") +var dst = flag.String("dst", "", "Destination database DSN") +var fraction = flag.Float64("f", 0.05, "Fraction of rows to copy") func main() { flag.Parse() log.Info().Msg("Starting") + if *src == "" || *dst == "" { + log.Fatal().Msg("Source and destination DSNs are required") + } + + if *fraction <= 0 || *fraction > 1 { + log.Fatal().Msg("Fraction must be between 0 and 1") + } + } diff --git a/subsetter/db_test.go b/subsetter/db_test.go index 543599a..cc17233 100644 --- a/subsetter/db_test.go +++ b/subsetter/db_test.go @@ -41,8 +41,7 @@ func populateTestsWithData(conn *pgx.Conn, table string, size int) { for i := 0; i < size; i++ { query := fmt.Sprintf("INSERT INTO %s (text) VALUES ('test%d') RETURNING id", table, i) var row string - err := conn.QueryRow(context.Background(), query).Scan(&row) - fmt.Println(err) + conn.QueryRow(context.Background(), query).Scan(&row) query = fmt.Sprintf("INSERT INTO relation (simple_id) VALUES ('%v')", row) conn.Exec(context.Background(), query)