Skip to content

Commit

Permalink
IT WORKS
Browse files Browse the repository at this point in the history
the trigger is set up so the course credits in pathway_field are filled via the course_master table

Co-Authored-By: walshm7 <[email protected]>
  • Loading branch information
anthony-basnight and walshm7 committed Nov 14, 2023
1 parent 4ecc3ee commit 51b4d0e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/api/db/pathway_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,18 @@ def create_trigger(self, conn):
"""
CREATE OR REPLACE FUNCTION fix_field() RETURNS TRIGGER AS $$
BEGIN
NEW.course_credits = 1;
NEW.desc_credit_level = 1;
NEW.desc_course_level = 1;
NEW.course_credits = COALESCE(
( SELECT cm.max_credits
FROM course_master cm JOIN pathway_field pf
ON UPPER(SPLIT_PART(pf.course_name, '- ', 2)) = cm.title
LIMIT 1
)
, -2);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER fix_field AFTER INSERT ON pathway_field
CREATE TRIGGER fix_field BEFORE INSERT ON pathway_field
FOR EACH ROW EXECUTE FUNCTION fix_field();
""")
print('transaction completed, exiting function')
Expand Down

0 comments on commit 51b4d0e

Please sign in to comment.