-- +goose Up
CREATE VIEW transactions_by_month AS 
        SELECT extract(year from transactions.date) as year, extract(month from transactions.date) as month, transactions.category_id, accounts.budget_id, SUM(amount) as amount
        FROM transactions
        INNER JOIN accounts ON accounts.id = transactions.account_id
        GROUP BY extract(year from transactions.date), extract(month from transactions.date), transactions.category_id, accounts.budget_id;

CREATE VIEW assignments_by_month AS 
        SELECT extract(year from assignments.date) as year, extract(month from assignments.date) as month, 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 extract(year from assignments.date), extract(month from assignments.date), assignments.category_id, category_groups.budget_id;

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