~singpolyma/jmp-schemas

dd34d379b537c033b37c2bdc093f9af1e9fcecf2 — Stephen Paul Weber 2 years ago 48bc71e
invites table

Table to store invite codes and their status.  Stores who make the code and
when, who used the code (if anyone has used it yet) and when, and the code
itself. Codes are single-use so once used_by_id is set the code cannot be used again.
5 files changed, 35 insertions(+), 0 deletions(-)

M .builds/debian-stable.yml
A deploy/invites.sql
A revert/invites.sql
M sqitch.plan
A verify/invites.sql
M .builds/debian-stable.yml => .builds/debian-stable.yml +2 -0
@@ 11,6 11,8 @@ tasks:
    sudo -u postgres psql -c "CREATE ROLE $(id -un) LOGIN"
    sudo -u postgres psql -c "CREATE DATABASE jmp WITH OWNER $(id -un)"
    sudo -u postgres psql -d jmp -c "CREATE EXTENSION btree_gist"
    sudo -u postgres psql -d jmp -c "CREATE EXTENSION citext"
    sudo -u postgres psql -d jmp -c "CREATE EXTENSION pgcrypto"
- deploy: |
    cd jmp-schemas
    sqitch deploy

A deploy/invites.sql => deploy/invites.sql +17 -0
@@ 0,0 1,17 @@
-- Deploy jmp:invites to pg

BEGIN;

CREATE TABLE invites (
	creator_id TEXT NOT NULL,
	used_by_id TEXT,
	created_at TIMESTAMP NOT NULL DEFAULT(LOCALTIMESTAMP),
	used_at    TIMESTAMP,
	code       CITEXT NOT NULL PRIMARY KEY
	           DEFAULT(UPPER(ENCODE(GEN_RANDOM_BYTES(4), 'hex')))
);

CREATE INDEX ON invites (creator_id, created_at DESC);
CREATE INDEX ON invites (used_by_id, used_at DESC);

COMMIT;

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

BEGIN;

DROP TABLE invites;

COMMIT;

M sqitch.plan => sqitch.plan +2 -0
@@ 11,3 11,5 @@ cdr 2021-02-24T18:36:49Z Stephen Paul Weber <singpolyma@singpolyma.net> # Create

plan_log_with_range [plan_log customer_plans] 2021-05-03T19:30:36Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Switch plan_log to use a tsrange
@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

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

BEGIN;

SELECT creator_id, used_by_id, created_at, used_at, code FROM invites;

ROLLBACK;