From 8b6a8c369731c88f570452a97976cb8ed6608012 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Sat, 11 Dec 2021 22:08:08 +0000 Subject: [PATCH] Add income_category_id only after categories table exists --- postgres/schema/0002_budgets.sql | 3 +-- postgres/schema/0008_categories.sql | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/postgres/schema/0002_budgets.sql b/postgres/schema/0002_budgets.sql index 6d7de91..828f1d0 100644 --- a/postgres/schema/0002_budgets.sql +++ b/postgres/schema/0002_budgets.sql @@ -2,8 +2,7 @@ CREATE TABLE budgets ( id uuid DEFAULT uuid_generate_v4() PRIMARY KEY, name text NOT NULL, - last_modification timestamp with time zone, - income_category_id uuid NOT NULL REFERENCES categories (id) DEFERRABLE + last_modification timestamp with time zone ); -- +goose Down diff --git a/postgres/schema/0008_categories.sql b/postgres/schema/0008_categories.sql index 908f680..cb64403 100644 --- a/postgres/schema/0008_categories.sql +++ b/postgres/schema/0008_categories.sql @@ -4,6 +4,8 @@ CREATE TABLE categories ( category_group_id uuid NOT NULL REFERENCES category_groups (id) ON DELETE CASCADE, name varchar(50) NOT NULL ); +ALTER TABLE budgets ADD COLUMN income_category_id uuid NOT NULL REFERENCES categories (id) DEFERRABLE; -- +goose Down +ALTER TABLE budgets DROP COLUMN income_category_id; DROP TABLE categories; \ No newline at end of file