X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=database%2Ffunctions%2Fraid_claims.sql;fp=database%2Ffunctions%2Fraid_claims.sql;h=2daac291c85526a8e7f3f942856cced9e63621bb;hb=76887e53c27118fe04ae8fe75dce610a398b5853;hp=0000000000000000000000000000000000000000;hpb=73119e806350719e2ce899bfbaa2ba19f0dc87d1;p=ndwebbie.git diff --git a/database/functions/raid_claims.sql b/database/functions/raid_claims.sql new file mode 100644 index 0000000..2daac29 --- /dev/null +++ b/database/functions/raid_claims.sql @@ -0,0 +1,35 @@ +CREATE OR REPLACE FUNCTION updated_claim() RETURNS trigger + AS $_X$ +DECLARE + target INTEGER; +BEGIN + CASE TG_OP + WHEN 'INSERT' THEN + target := NEW.target; + WHEN 'UPDATE' THEN + target := NEW.target; + IF NEW.launched AND NOT OLD.launched THEN + UPDATE users + SET attack_points = attack_points + 1 + WHERE uid = OLD.uid; + + INSERT INTO forum_posts (ftid,uid,message) + VALUES((SELECT ftid FROM users WHERE uid = NEW.uid),NEW.uid + ,'Gave attack point for confirmation of attack on target ' + || NEW.target || ', wave ' || NEW.wave + ); + END IF; + WHEN 'DELETE' THEN + target := OLD.target; + + IF OLD.launched THEN + UPDATE users + SET attack_points = attack_points - 1 + WHERE uid = OLD.uid; + END IF; + END CASE; + UPDATE raid_targets SET modified = NOW() WHERE id = target; + RETURN NEW; +END; +$_X$ LANGUAGE plpgsql; +