Skip to content
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

SQL: fix function definition of ticket_dependee_missing #200

Merged
merged 2 commits into from
Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SET ROLE TO postgres;
-- returns true if:
-- - given ID is an encoding ticket
-- - given ID's profile does have a dependency
-- - that dependency is not met in the given ID's project
-- - no encoding ticket among the given ID's sibling tickets has that dependee profile
-- In all other cases, including the cases where this check does not
-- make any sense, it will return false.

Expand Down Expand Up @@ -37,7 +37,7 @@ BEGIN
WHERE
depender.id = param_depender_ticket_id;

RETURN result;
RETURN COALESCE(result, false);

END
$$
Expand Down
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
LEFT 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 COALESCE(result, false);

END
$$
LANGUAGE plpgsql;

COMMIT;