-
Notifications
You must be signed in to change notification settings - Fork 15
chore: migrate workflows to db #818
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| -- name: GetWorkflowByID :one | ||
| SELECT id, name, inputs, jobs, workspace_id FROM workflow WHERE id = $1; | ||
|
|
||
| -- name: ListWorkflowsByWorkspaceID :many | ||
| SELECT id, name, inputs, jobs, workspace_id FROM workflow WHERE workspace_id = $1; | ||
|
|
||
| -- name: UpsertWorkflow :one | ||
| INSERT INTO workflow (id, name, inputs, jobs, workspace_id) VALUES ($1, $2, $3, $4, $5) | ||
| ON CONFLICT (id) DO UPDATE SET name = EXCLUDED.name, inputs = EXCLUDED.inputs, jobs = EXCLUDED.jobs | ||
| RETURNING *; | ||
|
|
||
| -- name: DeleteWorkflow :exec | ||
| DELETE FROM workflow WHERE id = $1; | ||
|
|
||
| -- name: GetWorkflowJobTemplateByID :one | ||
| SELECT id, workflow_id, name, ref, config, if_condition, matrix FROM workflow_job_template WHERE id = $1; | ||
|
|
||
| -- name: ListWorkflowJobTemplatesByWorkspaceID :many | ||
| SELECT wjt.id, wjt.workflow_id, wjt.name, wjt.ref, wjt.config, wjt.if_condition, wjt.matrix | ||
| FROM workflow_job_template wjt | ||
| INNER JOIN workflow w ON w.id = wjt.workflow_id | ||
| WHERE w.workspace_id = $1; | ||
|
|
||
| -- name: UpsertWorkflowJobTemplate :one | ||
| INSERT INTO workflow_job_template (id, workflow_id, name, ref, config, if_condition, matrix) VALUES ($1, $2, $3, $4, $5, $6, $7) | ||
| ON CONFLICT (id) DO UPDATE SET workflow_id = EXCLUDED.workflow_id, name = EXCLUDED.name, ref = EXCLUDED.ref, config = EXCLUDED.config, if_condition = EXCLUDED.if_condition, matrix = EXCLUDED.matrix | ||
| RETURNING *; | ||
|
|
||
| -- name: DeleteWorkflowJobTemplate :exec | ||
| DELETE FROM workflow_job_template WHERE id = $1; | ||
|
|
||
| -- name: GetWorkflowRunByID :one | ||
| SELECT id, workflow_id, inputs FROM workflow_run WHERE id = $1; | ||
|
|
||
| -- name: ListWorkflowRunsByWorkflowID :many | ||
| SELECT id, workflow_id, inputs FROM workflow_run WHERE workflow_id = $1; | ||
|
|
||
| -- name: ListWorkflowRunsByWorkspaceID :many | ||
| SELECT wr.id, wr.workflow_id, wr.inputs | ||
| FROM workflow_run wr | ||
| INNER JOIN workflow w ON w.id = wr.workflow_id | ||
| WHERE w.workspace_id = $1; | ||
|
|
||
| -- name: UpsertWorkflowRun :one | ||
| INSERT INTO workflow_run (id, workflow_id, inputs) VALUES ($1, $2, $3) | ||
| ON CONFLICT (id) DO UPDATE SET workflow_id = EXCLUDED.workflow_id, inputs = EXCLUDED.inputs | ||
| RETURNING *; | ||
|
|
||
| -- name: DeleteWorkflowRun :exec | ||
| DELETE FROM workflow_run WHERE id = $1; | ||
|
|
||
| -- name: GetWorkflowJobByID :one | ||
| SELECT id, workflow_run_id, ref, config, index FROM workflow_job WHERE id = $1; | ||
|
|
||
| -- name: ListWorkflowJobsByWorkflowRunID :many | ||
| SELECT id, workflow_run_id, ref, config, index FROM workflow_job WHERE workflow_run_id = $1 ORDER BY index ASC; | ||
|
|
||
| -- name: ListWorkflowJobsByWorkspaceID :many | ||
| SELECT wj.id, wj.workflow_run_id, wj.ref, wj.config, wj.index | ||
| FROM workflow_job wj | ||
| INNER JOIN workflow_run wr ON wr.id = wj.workflow_run_id | ||
| INNER JOIN workflow w ON w.id = wr.workflow_id | ||
| WHERE w.workspace_id = $1 | ||
| ORDER BY wj.index ASC; | ||
|
|
||
| -- name: UpsertWorkflowJob :one | ||
| INSERT INTO workflow_job (id, workflow_run_id, ref, config, index) VALUES ($1, $2, $3, $4, $5) | ||
| ON CONFLICT (id) DO UPDATE SET workflow_run_id = EXCLUDED.workflow_run_id, ref = EXCLUDED.ref, config = EXCLUDED.config, index = EXCLUDED.index | ||
| RETURNING *; | ||
|
|
||
| -- name: DeleteWorkflowJob :exec | ||
| DELETE FROM workflow_job WHERE id = $1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Add indexes on workflow foreign keys in SQLC schema.
These FK columns should be indexed to keep list/query paths and cascading cleanup performant.
📌 Suggested SQL additions
CREATE TABLE workflow_job ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), workflow_run_id UUID NOT NULL REFERENCES workflow_run(id) ON DELETE CASCADE, ref TEXT NOT NULL, config JSONB NOT NULL DEFAULT '{}', index INTEGER NOT NULL DEFAULT 0 ); + +CREATE INDEX workflow_workspace_id_idx ON workflow(workspace_id); +CREATE INDEX workflow_job_template_workflow_id_idx ON workflow_job_template(workflow_id); +CREATE INDEX workflow_run_workflow_id_idx ON workflow_run(workflow_id); +CREATE INDEX workflow_job_workflow_run_id_idx ON workflow_job(workflow_run_id);📝 Committable suggestion
🤖 Prompt for AI Agents
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.
premature optimiziation
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.
@adityachoudhari26, understood! You can always add these indexes later if query performance becomes a concern.✏️ Learnings added
🧠 Learnings used