Add accounts & payees

This commit is contained in:
2021-11-29 22:52:58 +00:00
parent 6df72dc40d
commit 37d19733df
5 changed files with 61 additions and 6 deletions

View File

@ -0,0 +1,37 @@
-- +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;