~singpolyma/jmp-schemas

e005a4d6b09636d21614be0c513ce9360cef2ccb — Stephen Paul Weber 10 months ago 9b7bc1f
View for the most current plan for each customer

This includes a plan even if it is expired, with the expires_at present for
checking if desired.  This is because an expired user may still want to may a
payment or similar, and checking their plan is how we know what currency to
charge them in.
4 files changed, 33 insertions(+), 0 deletions(-)

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

BEGIN;

CREATE VIEW customer_plans AS
	SELECT DISTINCT ON (customer_id)
		customer_id,
		plan_name,
		expires_at
	FROM plan_log
	WHERE starts_at <= NOW()
	ORDER BY customer_id, starts_at DESC;

COMMIT;

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

BEGIN;

DROP VIEW customer_plans;

COMMIT;

M sqitch.plan => sqitch.plan +1 -0
@@ 5,3 5,4 @@ transactions 2021-02-22T19:15:25Z Stephen Paul Weber <singpolyma@singpolyma.net>
balances 2021-02-23T15:08:09Z Stephen Paul Weber <singpolyma@singpolyma.net> # Creates a view to lookup customer balances
sub_cent_transactions 2021-02-24T01:37:35Z Stephen Paul Weber <singpolyma@singpolyma.net> # Minutes cost less than 1 cent, so we need more decimal places
plan_log 2021-02-24T01:53:29Z Stephen Paul Weber <singpolyma@singpolyma.net> # Log to show what plans an account has had
customer_plans 2021-02-24T02:06:25Z Stephen Paul Weber <singpolyma@singpolyma.net> # View of current customer plans

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

BEGIN;

SELECT
	customer_id,
	plan_name,
	expires_at
FROM customer_plans;

ROLLBACK;