-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/Application/Migrations/__2019-01-03_fix-dependee-ticket-missing.sql
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,38 @@ | ||
BEGIN; | ||
|
||
SET ROLE TO postgres; | ||
|
||
CREATE OR REPLACE FUNCTION ticket_dependee_missing(param_depender_ticket_id bigint) | ||
RETURNS boolean AS | ||
$$ | ||
DECLARE | ||
result boolean; | ||
BEGIN | ||
|
||
SELECT | ||
epv.id IS NOT NULL -- check this is actually an encoding ticket | ||
AND ep.depends_on IS NOT NULL -- check that this is a ticket of a depending profile | ||
AND dependee.id IS NULL -- this is the error condition to return true on | ||
INTO result | ||
FROM | ||
tbl_ticket depender | ||
LEFT JOIN | ||
tbl_encoding_profile_version epv ON epv.id = depender.encoding_profile_version_id | ||
LEFT JOIN | ||
tbl_encoding_profile ep ON epv.encoding_profile_id = ep.id | ||
LEFT JOIN | ||
tbl_encoding_profile ep2 ON ep2.id = ep.depends_on | ||
LEFT JOIN | ||
tbl_encoding_profile_version epv2 ON epv2.encoding_profile_id = ep2.id | ||
INNER JOIN | ||
tbl_ticket dependee ON dependee.encoding_profile_version_id = epv2.id AND dependee.parent_id = depender.parent_id | ||
WHERE | ||
depender.id = param_depender_ticket_id; | ||
|
||
RETURN result; | ||
|
||
END | ||
$$ | ||
LANGUAGE plpgsql; | ||
|
||
COMMIT; |