~singpolyma/jmp-schemas

90c65e03df439876d7b8c22d0493151323e7b2df — Stephen Paul Weber 3 years ago b0729ab
Allow sub-cent transactions for minute billing
A deploy/sub_cent_transactions.sql => deploy/sub_cent_transactions.sql +16 -0
@@ 0,0 1,16 @@
-- Deploy jmp:sub_cent_transactions to pg

BEGIN;

DROP VIEW balances; -- Cannot alter column type while view exists

ALTER TABLE transactions ALTER COLUMN amount TYPE NUMERIC(12,4);

CREATE VIEW balances AS
	SELECT
		customer_id,
		SUM(amount) AS balance
	FROM transactions
	GROUP BY customer_id;

COMMIT;

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

BEGIN;

ALTER TABLE transactions ALTER COLUMN TYPE NUMERIC(12,2);

COMMIT;

M sqitch.plan => sqitch.plan +1 -0
@@ 3,3 3,4 @@

transactions 2021-02-22T19:15:25Z Stephen Paul Weber <singpolyma@singpolyma.net> # Creates a table to track user's transactions
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

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

BEGIN;

INSERT INTO transactions (customer_id, transaction_id, amount)
	VALUES ('customer', 'sqitch-test', 12.1234);

SELECT 1/COUNT(1) FROM transactions WHERE
	transaction_id = 'sqitch-test' AND
	amount = 12.1234;

DELETE FROM transactions WHERE transaction_id = 'sqitch-test';

ROLLBACK;