1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2024-12-30 10:11:23 +02:00

Don't return extra columns in result set

Since commit 360708e93d the feed-latest-build query has returned extra columns in the results, causing log messages like the following:

```
meddler.Targets: column [build_repo_id] not found in struct
meddler.Targets: column [build_id] not found in struct
meddler.WriteTargets: column [build_repo_id] not found in struct
meddler.WriteTargets: column [build_id] not found in struct
```

This is a result of the optimised Postgres query including the `build_repo_id` and `build_id` terms, where previously they were not inclued.
This PR rewrites the query slightly to produce the expected result set (i.e. without the `build_repo_id` and `build_id` columns). As a side-effect it also looks similar to the original query.

Signed-off-by: Niall Sheridan <nsheridan@squarespace.com>
This commit is contained in:
Niall Sheridan 2018-11-13 14:25:42 +00:00
parent bc22e226d0
commit 4949047575
2 changed files with 44 additions and 8 deletions

View File

@ -1,10 +1,28 @@
-- name: feed-latest-build
SELECT repo_owner, repo_name, repo_full_name, b.*
SELECT
repo_owner
,repo_name
,repo_full_name
,build_number
,build_event
,build_status
,build_created
,build_started
,build_finished
,build_commit
,build_branch
,build_ref
,build_refspec
,build_remote
,build_title
,build_message
,build_author
,build_email
,build_avatar
FROM repos LEFT OUTER JOIN (
SELECT DISTINCT ON (build_repo_id) build_repo_id, build_id, build_number, build_event, build_status, build_created, build_started, build_finished, build_commit, build_branch, build_ref, build_refspec, build_remote, build_title, build_message, build_author, build_email, build_avatar
FROM builds
ORDER BY build_repo_id, build_id DESC
SELECT DISTINCT ON (build_repo_id) * FROM builds
ORDER BY build_repo_id, build_id DESC
) b ON b.build_repo_id = repos.repo_id
INNER JOIN perms ON perms.perm_repo_id = repos.repo_id
WHERE perms.perm_user_id = $1

View File

@ -98,11 +98,29 @@ SELECT currval('builds_build_id_seq');
`
var feedLatestBuild = `
SELECT repo_owner, repo_name, repo_full_name, b.*
SELECT
repo_owner
,repo_name
,repo_full_name
,build_number
,build_event
,build_status
,build_created
,build_started
,build_finished
,build_commit
,build_branch
,build_ref
,build_refspec
,build_remote
,build_title
,build_message
,build_author
,build_email
,build_avatar
FROM repos LEFT OUTER JOIN (
SELECT DISTINCT ON (build_repo_id) build_repo_id, build_id, build_number, build_event, build_status, build_created, build_started, build_finished, build_commit, build_branch, build_ref, build_refspec, build_remote, build_title, build_message, build_author, build_email, build_avatar
FROM builds
ORDER BY build_repo_id, build_id DESC
SELECT DISTINCT ON (build_repo_id) * FROM builds
ORDER BY build_repo_id, build_id DESC
) b ON b.build_repo_id = repos.repo_id
INNER JOIN perms ON perms.perm_repo_id = repos.repo_id
WHERE perms.perm_user_id = $1