~singpolyma/jmp-schemas

6d61018ed0bf00ef9c200fefd076ed60d0fc3bd2 — Stephen Paul Weber 2 years ago 6e5297a
Merge sub_cent_transaction plan item into transactions

Since none of this is deployed or tagged yet, there's no reason for the overly
complex alter table schenanigans.  We have to leave the empty plan item though,
since it's in the git history and otherwise sqitch rebase would break

Will get the hang of this tooling!
M deploy/sub_cent_transactions.sql => deploy/sub_cent_transactions.sql +3 -14
@@ 1,16 1,5 @@
-- 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;
-- This has been folded in to the transactions plan item
-- There is no good reason to use a complex alter for something that has never
-- been deployed, devs can just use sqitch checkout or sqitch rebase

M deploy/transactions.sql => deploy/transactions.sql +1 -1
@@ 6,7 6,7 @@ CREATE TABLE transactions (
	customer_id    TEXT          NOT NULL,
	transaction_id TEXT          PRIMARY KEY,
	created_at     timestamp     NOT NULL DEFAULT(NOW()),
	amount         NUMERIC(12,2) NOT NULL
	amount         NUMERIC(12,4) NOT NULL
);

CREATE INDEX ON transactions (customer_id, created_at DESC);

M revert/cdr.sql => revert/cdr.sql +1 -0
@@ 3,5 3,6 @@
BEGIN;

DROP TABLE cdr;
DROP TYPE call_direction;

COMMIT;

M revert/sub_cent_transactions.sql => revert/sub_cent_transactions.sql +1 -5
@@ 1,7 1,3 @@
-- Revert jmp:sub_cent_transactions from pg

BEGIN;

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

COMMIT;
-- See deploy file

M verify/sub_cent_transactions.sql => verify/sub_cent_transactions.sql +1 -12
@@ 1,14 1,3 @@
-- 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;
-- See deploy file