-- +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;