~singpolyma/jmp-schemas

1bef640493ff0409838c71e72dd105fb61473cb5 — Stephen Paul Weber 2 years ago dd34d37
unused_invites view

View to get all invites not yet used up.
4 files changed, 32 insertions(+), 0 deletions(-)

A deploy/unused_invites.sql
A revert/unused_invites.sql
M sqitch.plan
A verify/unused_invites.sql
A deploy/unused_invites.sql => deploy/unused_invites.sql +10 -0
@@ 0,0 1,10 @@
-- Deploy jmp:unused_invites to pg

BEGIN;

CREATE VIEW unused_invites AS
	SELECT creator_id, created_at, code
	FROM invites
	WHERE used_by_id IS NULL;

COMMIT;

A revert/unused_invites.sql => revert/unused_invites.sql +7 -0
@@ 0,0 1,7 @@
-- Revert jmp:unused_invites from pg

BEGIN;

DROP VIEW unused_invites;

COMMIT;

M sqitch.plan => sqitch.plan +1 -0
@@ 13,3 13,4 @@ plan_log_with_range [plan_log customer_plans] 2021-05-03T19:30:36Z Stephen Paul 
@2021130 2021-05-11T01:37:34Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Deploy to production

invites 2021-05-17T20:31:00Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Table to store invite codes and their state
unused_invites 2021-05-17T20:40:20Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # View for invites not yet used

A verify/unused_invites.sql => verify/unused_invites.sql +14 -0
@@ 0,0 1,14 @@
-- Verify jmp:unused_invites on pg

BEGIN;

INSERT INTO invites (creator_id)
	VALUES ('boop');
INSERT INTO invites (creator_id, used_by_id, used_at)
	VALUES ('boop', 'otherone', LOCALTIMESTAMP);

SELECT 1/count(1) FROM (
	SELECT count(1) AS a FROM unused_invites WHERE creator_id='boop'
) s WHERE a = 1;

ROLLBACK;