-- +goose Up
CREATE OR REPLACE VIEW transactions_by_month AS 
        SELECT date_trunc('month', transactions.date)::date as date, transactions.category_id, accounts.budget_id, SUM(amount) as amount
        FROM transactions
        INNER JOIN accounts ON accounts.id = transactions.account_id AND accounts.on_budget
        GROUP BY date_trunc('month', transactions.date), transactions.category_id, accounts.budget_id;

-- +goose Down
CREATE OR REPLACE VIEW transactions_by_month AS 
        SELECT date_trunc('month', transactions.date)::date as date, transactions.category_id, accounts.budget_id, SUM(amount) as amount
        FROM transactions
        INNER JOIN accounts ON accounts.id = transactions.account_id
        GROUP BY date_trunc('month', transactions.date), transactions.category_id, accounts.budget_id;