-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support upserts #292
Labels
Comments
iand
added
kind/enhancement
Improvement to an existing feature
P2
P2: Should be resolved
labels
Dec 2, 2020
From the looks of go-pg documentation: https://pkg.go.dev/github.com/go-pg/pg/v10#example-DB.Model-InsertOnConflictDoUpdate it doesn't have "easy" support for upsert. For comparison, GORM allows upserts to be performed via: https://gorm.io/docs/create.html#Upsert-On-Conflict |
As an example, will probably go with something like? func (a *Actor) PersistWithTx(ctx context.Context, tx *pg.Tx, policy model.ConflictPolicy) error {
ctx, span := global.Tracer("").Start(ctx, "Actor.PersistWithTx")
defer span.End()
q := tx.ModelContext(ctx, a)
if policy == model.DoNothing {
if _, err := q.OnConflict("do nothing").
Insert(); err != nil {
return err
}
} else if policy == model.Upset {
if _, err := q.OnConflict("(state_root)").
Set("code = ?code, head = ?head, balance = ?balance, nonce = ?nonce").
Insert(); err != nil {
return err
}
} else {
return xerrors.Errorf("unknown conflict policy: %d", policy)
}
return nil
}
|
Merged
frrist
added a commit
that referenced
this issue
Dec 16, 2020
frrist
added a commit
that referenced
this issue
Dec 16, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Currently all Visor models are inserted using
ON CONFLICT DO NOTHING
which discards the data if it conflicts with existing data. This is fine for appending new data but unsatisfactory when backfilling after changes to extraction logic or bug fixes. Visor should support upserting of data if a conflict is encountered. We may want to make this an optional flag for use when backfilling since in normal operation all writes are appends.Acceptance criteria
Where to begin
OnConflict
clause call in each model's persist method to update the non primary key columns.The text was updated successfully, but these errors were encountered: