chore: join user information to workspace_build and template_version (#8625)

* include minimial user on template version and build
* Add unit test to ensure join is superset
This commit is contained in:
Steven Masley
2023-07-25 09:14:38 -04:00
committed by GitHub
parent fbb2a6a434
commit de1a7a9210
39 changed files with 819 additions and 717 deletions
+12 -12
View File
@@ -2,7 +2,7 @@
SELECT
*
FROM
template_versions
template_version_with_user AS template_versions
WHERE
template_id = @template_id :: uuid
AND CASE
@@ -36,18 +36,18 @@ LIMIT
SELECT
*
FROM
template_versions
template_version_with_user AS template_versions
WHERE
job_id = $1;
-- name: GetTemplateVersionsCreatedAfter :many
SELECT * FROM template_versions WHERE created_at > $1;
SELECT * FROM template_version_with_user AS template_versions WHERE created_at > $1;
-- name: GetTemplateVersionByTemplateIDAndName :one
SELECT
*
FROM
template_versions
template_version_with_user AS template_versions
WHERE
template_id = $1
AND "name" = $2;
@@ -56,7 +56,7 @@ WHERE
SELECT
*
FROM
template_versions
template_version_with_user AS template_versions
WHERE
id = $1;
@@ -64,11 +64,11 @@ WHERE
SELECT
*
FROM
template_versions
template_version_with_user AS template_versions
WHERE
id = ANY(@ids :: uuid [ ]);
-- name: InsertTemplateVersion :one
-- name: InsertTemplateVersion :exec
INSERT INTO
template_versions (
id,
@@ -83,9 +83,9 @@ INSERT INTO
created_by
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *;
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);
-- name: UpdateTemplateVersionByID :one
-- name: UpdateTemplateVersionByID :exec
UPDATE
template_versions
SET
@@ -94,7 +94,7 @@ SET
name = $4,
message = $5
WHERE
id = $1 RETURNING *;
id = $1;
-- name: UpdateTemplateVersionDescriptionByJobID :exec
UPDATE
@@ -118,11 +118,11 @@ WHERE
SELECT
*
FROM
template_versions
template_version_with_user AS template_versions
WHERE
created_at < (
SELECT created_at
FROM template_versions AS tv
FROM template_version_with_user AS tv
WHERE tv.organization_id = $1 AND tv.name = $2 AND tv.template_id = $3
)
AND organization_id = $1
+16 -16
View File
@@ -2,7 +2,7 @@
SELECT
*
FROM
workspace_builds
workspace_build_with_user AS workspace_builds
WHERE
id = $1
LIMIT
@@ -12,20 +12,20 @@ LIMIT
SELECT
*
FROM
workspace_builds
workspace_build_with_user AS workspace_builds
WHERE
job_id = $1
LIMIT
1;
-- name: GetWorkspaceBuildsCreatedAfter :many
SELECT * FROM workspace_builds WHERE created_at > $1;
SELECT * FROM workspace_build_with_user WHERE created_at > $1;
-- name: GetWorkspaceBuildByWorkspaceIDAndBuildNumber :one
SELECT
*
FROM
workspace_builds
workspace_build_with_user AS workspace_builds
WHERE
workspace_id = $1
AND build_number = $2;
@@ -34,7 +34,7 @@ WHERE
SELECT
*
FROM
workspace_builds
workspace_build_with_user AS workspace_builds
WHERE
workspace_builds.workspace_id = $1
AND workspace_builds.created_at > @since
@@ -67,7 +67,7 @@ LIMIT
SELECT
*
FROM
workspace_builds
workspace_build_with_user AS workspace_builds
WHERE
workspace_id = $1
ORDER BY
@@ -81,14 +81,14 @@ FROM (
SELECT
workspace_id, MAX(build_number) as max_build_number
FROM
workspace_builds
workspace_build_with_user AS workspace_builds
WHERE
workspace_id = ANY(@ids :: uuid [ ])
GROUP BY
workspace_id
) m
JOIN
workspace_builds wb
workspace_build_with_user AS wb
ON m.workspace_id = wb.workspace_id AND m.max_build_number = wb.build_number;
-- name: GetLatestWorkspaceBuilds :many
@@ -97,15 +97,15 @@ FROM (
SELECT
workspace_id, MAX(build_number) as max_build_number
FROM
workspace_builds
workspace_build_with_user AS workspace_builds
GROUP BY
workspace_id
) m
JOIN
workspace_builds wb
workspace_build_with_user AS wb
ON m.workspace_id = wb.workspace_id AND m.max_build_number = wb.build_number;
-- name: InsertWorkspaceBuild :one
-- name: InsertWorkspaceBuild :exec
INSERT INTO
workspace_builds (
id,
@@ -123,9 +123,9 @@ INSERT INTO
reason
)
VALUES
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING *;
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);
-- name: UpdateWorkspaceBuildByID :one
-- name: UpdateWorkspaceBuildByID :exec
UPDATE
workspace_builds
SET
@@ -134,13 +134,13 @@ SET
deadline = $4,
max_deadline = $5
WHERE
id = $1 RETURNING *;
id = $1;
-- name: UpdateWorkspaceBuildCostByID :one
-- name: UpdateWorkspaceBuildCostByID :exec
UPDATE
workspace_builds
SET
daily_cost = $2
WHERE
id = $1 RETURNING *;
id = $1;