-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from psarando/CORE-1517
CORE-1517 Add app_versions_listing view
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,7 @@ | ||
BEGIN; | ||
|
||
SET search_path = public, pg_catalog; | ||
|
||
DROP VIEW IF EXISTS app_versions_listing; | ||
|
||
COMMIT; |
This file contains 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,48 @@ | ||
BEGIN; | ||
|
||
SET search_path = public, pg_catalog; | ||
|
||
-- | ||
-- A view containing the top-level information needed for app version listings. | ||
-- | ||
CREATE OR REPLACE VIEW app_versions_listing AS | ||
SELECT apps.id, | ||
apps."name", | ||
apps.description, | ||
apps.wiki_url, | ||
integration.integrator_name, | ||
integration.integrator_email, | ||
v.id AS version_id, | ||
v.version, | ||
v.version_order, | ||
v.deleted, | ||
v.disabled, | ||
v.integration_date, | ||
v.edited_date, | ||
COUNT(steps.*) AS step_count, | ||
COUNT(t.tool_id) AS tool_count, | ||
COUNT(t.external_app_id) AS external_app_count, | ||
COUNT(t.id) AS task_count, | ||
CASE WHEN COUNT(DISTINCT tt.name) = 0 THEN 'unknown' | ||
WHEN COUNT(DISTINCT tt.name) > 1 THEN 'mixed' | ||
ELSE MAX(tt.name) | ||
END AS overall_job_type, | ||
integration.user_id AS integrator_id, | ||
u.username AS integrator_username, | ||
array_agg(tt.name) as job_types | ||
FROM apps | ||
LEFT JOIN app_versions v ON apps.id = v.app_id | ||
LEFT JOIN integration_data integration ON integration.id = v.integration_data_id | ||
LEFT JOIN users u ON integration.user_id = u.id | ||
LEFT JOIN app_steps steps ON steps.app_version_id = v.id | ||
LEFT JOIN tasks t ON steps.task_id = t.id | ||
LEFT JOIN tools tool ON t.tool_id = tool.id | ||
LEFT JOIN tool_types tt ON tool.tool_type_id = tt.id | ||
GROUP BY apps.id, | ||
integration.integrator_name, | ||
integration.integrator_email, | ||
integration.user_id, | ||
u.username, | ||
v.id; | ||
|
||
COMMIT; |