-- +goose Up
CREATE 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;

CREATE VIEW assignments_by_month AS 
        SELECT date_trunc('month', assignments.date)::date as date, assignments.category_id, category_groups.budget_id, SUM(amount) as amount
        FROM assignments
        INNER JOIN categories ON categories.id = assignments.category_id
        INNER JOIN category_groups ON categories.category_group_id = category_groups.id
        GROUP BY date_trunc('month', assignments.date), assignments.category_id, category_groups.budget_id;

-- +goose Down
DROP VIEW transactions_by_month;
DROP VIEW assignments_by_month;