Skip to content
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

feat: abstract model storage and add csv output for walk command #316

Merged
merged 1 commit into from
Dec 15, 2020

Conversation

iand
Copy link
Contributor

@iand iand commented Dec 11, 2020

Introduce model.Storage and model.StorageBatch interfaces to abstract away the details of the underlying model storage system. model.Storage is analogous to a database, model.StorageBatch is analogous to a transaction. A task should call Storage.PersistBatch with a set of results to be persisted. The storage will call the Persist method on each result, passing in a model.StorageBatch. A model should persist itself by calling StorageBatch.PersistModel. A composite type such as a list of results or a struct containing result fields should call the Persist method on each of its sub-results to ensure that they are persisted correctly.

Replace all the direct references to go-pg with this pair of interfaces. Move a bunch of helpers to more appropriate packages.

Add a --csv=path flag which will cause Visor to write data to csv files at that path, one file per database table. This flag overrides any database connection string if supplied. In other words Visor will not write to both a database and csv files.

@codecov-io
Copy link

codecov-io commented Dec 11, 2020

Codecov Report

Merging #316 (c34dfd4) into master (96fae29) will increase coverage by 0.6%.
The diff coverage is 48.7%.

@@           Coverage Diff            @@
##           master    #316     +/-   ##
========================================
+ Coverage    44.9%   45.6%   +0.6%     
========================================
  Files          20      22      +2     
  Lines        1978    2075     +97     
========================================
+ Hits          890     947     +57     
- Misses        969     997     +28     
- Partials      119     131     +12     

@iand iand changed the title feat: add csv output to walk command feat: abstract model storage and add csv output for walk command Dec 14, 2020
@iand iand marked this pull request as ready for review December 14, 2020 16:22
@iand iand requested a review from frrist December 14, 2020 16:32
Copy link
Member

@frrist frrist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Stuff!!

Most of the changes here look fairly mechanical and I didn't review them too thoroughly.

I like that this centralizes access of go-pg. 🚢

Comment on lines +751 to +755
if _, err := s.tx.ModelContext(ctx, m).
OnConflict("do nothing").
Insert(); err != nil {
return xerrors.Errorf("persisting model: %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this change lands would you expect #292 to be addressed here via reflection, via an interface the model implements, or something different?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could either handle in a few ways:

a) automatic via reflection magic (would be ideal but I'm unsure)
b) the model's Persist method could pass some hints when it calls PersistModel
c) we could add an UpdateModel method to StorageBatch that allows more control over the persistence

Message: "msg1",
}

dir, err := ioutil.TempDir("", "TestCSVPersist")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use t.Name() as instead of TestCSVPersist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

@iand iand merged commit 4ae639c into master Dec 15, 2020
@iand iand deleted the iand/csv-output branch December 15, 2020 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants