Skip to content

Commit

Permalink
fix: Handle changesets including arrays of strings
Browse files Browse the repository at this point in the history
Handles: unsupported type []interface {}, a slice of interface
when the array is not empty
  • Loading branch information
13rac1 committed May 8, 2020
1 parent 0a73e83 commit c3ad1af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/axon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func main() {

err = checkTargetVersion(targetDBConn)
if err != nil {
logger.WithError(err).Fatal("unable to use target database")
logger.WithError(err).Fatal("unable to check target database version")
}

err = printSourceStats(sourceDBConn)
Expand Down
6 changes: 4 additions & 2 deletions cmd/axon/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func prepareQueryArgs(changesetCols []*warppipe.ChangesetColumn) ([]string, []st
// interface"
if reflect.ValueOf(c.Value).Len() == 0 {
c.Value = pq.Array(nil)
} else {
c.Value = pq.Array(c.Value)
}
}
cols = append(cols, c.Column)
Expand Down Expand Up @@ -132,7 +134,7 @@ func insertRow(sourceDB *sqlx.DB, targetDB *sqlx.DB, schema string, change *warp
// PG error codes: https://www.postgresql.org/docs/9.2/errcodes-appendix.html
pqe, ok := err.(*pq.Error)
if !ok {
return fmt.Errorf("failed to insert %s for query %s: %+v", change, removeDuplicateSpaces(query), err)
return fmt.Errorf("failed to insert %s for query %s args %s: %+v", change, removeDuplicateSpaces(query), args, err)
}
if pqe.Code.Name() == "unique_violation" {
// Ignore duplicates
Expand Down Expand Up @@ -169,7 +171,7 @@ func updateRow(targetDB *sqlx.DB, schema string, change *warppipe.Changeset, pri
if err != nil {
pqe, ok := err.(*pq.Error)
if !ok {
return fmt.Errorf("failed to update %s for query %s: %+v", change, removeDuplicateSpaces(query), err)
return fmt.Errorf("failed to update %s for query %s args %s: %+v", change, removeDuplicateSpaces(query), args, err)
}
if pqe.Code.Name() == "unique_violation" {
// Ignore duplicates
Expand Down

0 comments on commit c3ad1af

Please sign in to comment.