Skip to content

Commit

Permalink
Add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dz0ny committed Aug 11, 2023
1 parent 152b231 commit 371ae79
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.pgsql/data
.pgsql/data
bin
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

}
3 changes: 1 addition & 2 deletions subsetter/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 371ae79

Please sign in to comment.