forked from rchain-community/rchain-dbr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbr_triggers.sql
33 lines (32 loc) · 1 KB
/
dbr_triggers.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
delimiter //
drop trigger if exists percent_max_100_insert //
create trigger percent_max_100_insert
before insert on reward_vote for each row
begin
declare pct_tot int;
select coalesce(sum(percent), 0) into pct_tot
from reward_vote cur
where cur.pay_period = new.pay_period
and cur.issue_num = new.issue_num
and cur.voter = new.voter;
if(pct_tot + new.percent > 100) then
signal sqlstate '45000' set message_text = 'Your reward votes on this issue would exceed 100%.';
end if;
end
//
drop trigger if exists percent_max_100_update //
create trigger percent_max_100_update
before update on reward_vote
for each row
begin
declare pct_tot int;
select coalesce(sum(percent), 0) into pct_tot
from reward_vote cur
where cur.pay_period = new.pay_period
and cur.issue_num = new.issue_num
and cur.voter = new.voter;
if(pct_tot - old.percent + new.percent > 100) then
SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Your reward votes on this issue would exceed 100%.';
end if;
end
//