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 Apr 22, 2020
1 parent e93fd73 commit 959163a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 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,17 +134,18 @@ 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
// TODO: Should they be updated instead?
log.Printf("duplicate row insert skipped %s:", change)
// Always update, even on duplicate row.
err = updateColumnSequence(targetDB, change.Table, change.NewValues)
if err != nil {
return err
}
// DISABLED: Angel believes this is the problem. I doubt it, but trying won't hurt.
// err = updateColumnSequence(targetDB, change.Table, change.NewValues)
// if err != nil {
// return err
// }

return nil
}
Expand All @@ -169,7 +172,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 959163a

Please sign in to comment.