From 1437fc7b8d397969ce00409190282bfbf7a3ff5f Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Mon, 6 Dec 2021 20:36:10 +0000 Subject: [PATCH] Fix 0001_enable-uuid-ossp and reorder --- http/http.go | 4 +-- postgres/schema/0001_enable-uuid-ossp.sql | 5 ++++ postgres/schema/202112021109_initial.sql | 36 +++++++++++------------ 3 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 postgres/schema/0001_enable-uuid-ossp.sql diff --git a/http/http.go b/http/http.go index d49eb48..0e41296 100644 --- a/http/http.go +++ b/http/http.go @@ -73,10 +73,10 @@ func (h *Handler) Serve() { user := authenticated.Group("/user") user.GET("/logout", logout) - budget := api.Group("/budget") + budget := authenticated.Group("/budget") budget.POST("/new", h.newBudget) - transaction := api.Group("/transaction") + transaction := authenticated.Group("/transaction") transaction.POST("/new", h.newTransaction) transaction.POST("/import/ynab", h.importYNAB) diff --git a/postgres/schema/0001_enable-uuid-ossp.sql b/postgres/schema/0001_enable-uuid-ossp.sql new file mode 100644 index 0000000..0ab9a3c --- /dev/null +++ b/postgres/schema/0001_enable-uuid-ossp.sql @@ -0,0 +1,5 @@ +-- +goose Up +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +-- +goose Down +DROP EXTENSION "uuid-ossp"; \ No newline at end of file diff --git a/postgres/schema/202112021109_initial.sql b/postgres/schema/202112021109_initial.sql index 481cc04..a97e085 100644 --- a/postgres/schema/202112021109_initial.sql +++ b/postgres/schema/202112021109_initial.sql @@ -1,6 +1,4 @@ -- +goose Up -CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; - CREATE TABLE budgets ( id uuid DEFAULT uuid_generate_v4() PRIMARY KEY, name text NOT NULL, @@ -35,6 +33,20 @@ CREATE TABLE payees ( ); ALTER TABLE "payees" ADD FOREIGN KEY ("budget_id") REFERENCES "budgets" ("id"); +CREATE TABLE category_groups ( + id uuid DEFAULT uuid_generate_v4() PRIMARY KEY, + budget_id uuid NOT NULL, + name varchar(50) NOT NULL +); +ALTER TABLE "category_groups" ADD FOREIGN KEY ("budget_id") REFERENCES "budgets" ("id"); + +CREATE TABLE categories ( + id uuid DEFAULT uuid_generate_v4() PRIMARY KEY, + category_group_id uuid NOT NULL, + name varchar(50) NOT NULL +); +ALTER TABLE "categories" ADD FOREIGN KEY ("category_group_id") REFERENCES "category_groups" ("id"); + CREATE TABLE transactions ( id uuid DEFAULT uuid_generate_v4() PRIMARY KEY, date date NOT NULL, @@ -48,26 +60,12 @@ ALTER TABLE "transactions" ADD FOREIGN KEY ("account_id") REFERENCES "accounts" ALTER TABLE "transactions" ADD FOREIGN KEY ("payee_id") REFERENCES "payees" ("id"); ALTER TABLE "transactions" ADD FOREIGN KEY ("category_id") REFERENCES "categories" ("id"); -CREATE TABLE category_groups ( - id uuid DEFAULT uuid_generate_v4() PRIMARY KEY, - budget_id uuid NOT NULL, - name varchar(50) NOT NULL -); -ALTER TABLE "category_groups" ADD FOREIGN KEY ("budget_id") REFERENCES "budgets" ("id"); - -CREATE TABLE categories ( - id uuid DEFAULT uuid_generate_v4() PRIMARY KEY, - category_group_id uuid NOT NULL, - name varchar(50) NOT NULL -); -ALTER TABLE "categories" ADD FOREIGN KEY ("category_group_id") REFERENCES "category_group" ("id"); - - -- +goose Down DROP TABLE transactions; DROP TABLE accounts; DROP TABLE payees; +DROP TABLE categories; +DROP TABLE category_groups; DROP TABLE user_budgets; DROP TABLE budgets; -DROP TABLE users; -DROP EXTENSION "uuid-ossp"; \ No newline at end of file +DROP TABLE users; \ No newline at end of file