Fix 0001_enable-uuid-ossp and reorder
This commit is contained in:
5
postgres/schema/0001_enable-uuid-ossp.sql
Normal file
5
postgres/schema/0001_enable-uuid-ossp.sql
Normal file
@ -0,0 +1,5 @@
|
||||
-- +goose Up
|
||||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
-- +goose Down
|
||||
DROP EXTENSION "uuid-ossp";
|
@ -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";
|
||||
DROP TABLE users;
|
Reference in New Issue
Block a user