From 6f4e286b7a8a28c8b1357b45dae7f8bd147bd7ef Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Mon, 14 Mar 2022 19:46:21 +0000 Subject: [PATCH] Initialize last_reconciled from transactions --- postgres/schema/0018_reconciled-on.sql | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/postgres/schema/0018_reconciled-on.sql b/postgres/schema/0018_reconciled-on.sql index a8adb68..42a16ed 100644 --- a/postgres/schema/0018_reconciled-on.sql +++ b/postgres/schema/0018_reconciled-on.sql @@ -1,5 +1,12 @@ -- +goose Up ALTER TABLE accounts ADD COLUMN last_reconciled date NULL; +UPDATE accounts +SET last_reconciled = ( + SELECT MAX(transactions.date) + FROM transactions + WHERE transactions.account_id = accounts.id + AND transactions.status = 'Reconciled' +); -- +goose Down ALTER TABLE accounts DROP COLUMN last_reconciled; \ No newline at end of file