-
Notifications
You must be signed in to change notification settings - Fork 41
feat(data): Adds latest_run and updated_at fields to workflow model #1505
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
Conversation
Signed-off-by: Javier Rodriguez <javier@chainloop.dev>
migmartri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
| field.Bool("public").Default(false), | ||
| field.UUID("organization_id", uuid.UUID{}), | ||
| field.UUID("project_id", uuid.UUID{}), | ||
| field.UUID("latest_run", uuid.UUID{}).Optional().Nillable(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does nillable mean compared to optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Indicates that the field is not required when creating or updating an entity. The field can be omitted in the input data.Nillable: Indicates that the field can hold anil(ornullin SQL) value in the database.
| } | ||
|
|
||
| // Not efficient, we need to do a query limit = 1 grouped by workflowID | ||
| lastRun, err := getLastRun(ctx, workflow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice :)
|
|
||
| if r != nil { | ||
| lastRun, err := entWrToBizWr(ctx, r) | ||
| if latestRun := w.Edges.LatestWorkflowRun; latestRun != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we query if it's not here? We do that pattern in some other places, either take it from the preloaded edge or load it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I removed the workflowRun option from entWFToBizWF, I added WithLatestWorkflowRun() to all the places where we were previously fetching the latest workflow run on demand. This ensures it works the same as before. My concern with always fetching the latest workflow run when not found on the edge is that it could lead to unnecessary queries since the logic doesn't always use it.
I prefer to keep it this way, and we can update the query if we need the latest workflow run in the future.
| return nil, err | ||
| } | ||
|
|
||
| // Update the workflow with the last run reference |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that's in the transaction :)
This patch introduces two new columns in the
workflowstable:latest_runandupdated_at. These columns are designed to track the most recent run of a workflow and the last update time, respectively.Changes in Logic:
updated_atfield is set accordingly.entWrToBizWrfunction in the data package has been refactored to leverage direct edge relationships, eliminating the need for additional queries to fetch the latest run for specified workflows.Database Modifications:
latest_runandupdated_atcolumns in theworkflowstable.