~singpolyma/jmp-schemas

6b2466fa30f4384ec88abd6984bd21934558ccbd — Stephen Paul Weber 5 months ago 1b41034
Get customer data from Redis
4 files changed, 32 insertions(+), 0 deletions(-)

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

BEGIN;

CREATE FOREIGN TABLE raw_customer_data (key text, val text)
	SERVER redis_server
	OPTIONS (tablekeyprefix 'jmp_customer_');

CREATE VIEW customers AS
	SELECT
		MAX(SPLIT_PART(key, '-', 2)) AS customer_id,
		JSONB_OBJECT_AGG(SUBSTRING(SPLIT_PART(key, '-', 1) FROM 14), val) AS data
	FROM raw_customer_data
	WHERE key NOT LIKE 'jmp_customer_id-%' GROUP BY SPLIT_PART(key, '-', 2);

COMMIT;

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

BEGIN;

DROP VIEW customers;
DROP FOREIGN TABLE raw_customer_data;

COMMIT;

M sqitch.plan => sqitch.plan +1 -0
@@ 18,5 18,6 @@ invite_per_15 [transactions invites] 2021-08-18T17:46:38Z Stephen Paul Weber,,, 
call_rates 2021-11-17T01:29:07Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Table to store per-plan per-direction rates to different prefixes
cdr_with_charge [cdr call_rates customer_plans] 2021-11-17T01:44:14Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # View to get CDR records augmented with rate and charge amount
plans 2021-11-17T18:06:30Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Table for plan metadata\n\nIdeally this would come from a dhall_fdw, but for now we can import to this.
customers 2021-11-30T16:36:48Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Get customers from Redis\n\nRequires a redis_server to be configured on the postgres instance.
cdr_charge [customer_plans plans cdr_with_charge] 2021-11-17T18:09:49Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Get the amount to charge a customer for a given CDR
insert_charge_for_cdr [cdr_charge cdr_with_charge transactions] 2021-11-23T14:41:15Z Stephen Paul Weber,,, <singpolyma@singpolyma-beefy> # Trigger to insert a transaction for the charge for this CDR

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

BEGIN;

SELECT customer_id, data FROM customers;

ROLLBACK;