~singpolyma/jmp-schemas

ref: 589f2e6bed96c7d358b9daabb8ccddd57afb8b64 jmp-schemas/deploy/invite_per_15.sql -rw-r--r-- 524 bytes
589f2e6bStephen Paul Weber For every $15 deposited, add one invite code 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- Deploy jmp:invite_per_15 to pg
-- requires: transactions
-- requires: invites

BEGIN;

CREATE OR REPLACE FUNCTION insert_invites_per() RETURNS TRIGGER AS
$insert_invites_per$
	BEGIN
		FOR i IN 1..(NEW.amount::int / TG_ARGV[0]::int) LOOP
			INSERT INTO invites (creator_id) VALUES (NEW.customer_id);
		END LOOP;
		RETURN NEW;
	END;
$insert_invites_per$ LANGUAGE plpgsql;

CREATE TRIGGER invite_per_15
	AFTER INSERT ON transactions
	FOR EACH ROW
	WHEN (NEW.amount >= 15)
	EXECUTE PROCEDURE insert_invites_per(15);

COMMIT;