-- +goose Up
CREATE TABLE accounts (
        id uuid DEFAULT uuid_generate_v4() NOT NULL,
        budget_id uuid NOT NULL,
        name varchar(50) NOT NULL
);

CREATE TABLE payees (
        id uuid DEFAULT uuid_generate_v4() NOT NULL,
        budget_id uuid NOT NULL,
        name varchar(50) NOT NULL
);

TRUNCATE TABLE transactions;
ALTER TABLE transactions ADD COLUMN account_id uuid NOT NULL;
ALTER TABLE transactions ADD COLUMN payee_id uuid;



ALTER TABLE "user_budgets" ADD FOREIGN KEY ("user_id") REFERENCES "users" ("id");

ALTER TABLE "user_budgets" ADD FOREIGN KEY ("budget_id") REFERENCES "budgets" ("id");

ALTER TABLE "transactions" ADD FOREIGN KEY ("account_id") REFERENCES "accounts" ("id");

ALTER TABLE "accounts" ADD FOREIGN KEY ("budget_id") REFERENCES "budgets" ("id");

ALTER TABLE "categories" ADD FOREIGN KEY ("budget_id") REFERENCES "budgets" ("id");

ALTER TABLE "assignments" ADD FOREIGN KEY ("category_id") REFERENCES "categories" ("id");

-- +goose Down
ALTER TABLE transactions DROP COLUMN account_id;
ALTER TABLE transactions DROP COLUMN payee_id;

DROP TABLE accounts;
DROP TABLE payees;