From 2078e008f343cb71dfdc45dca4aef5b643d6a887 Mon Sep 17 00:00:00 2001 From: Fedorov Vladimir Date: Thu, 21 Nov 2024 01:02:15 +0700 Subject: [PATCH] update db --- migrations/20241120173848_add_budgets_table.sql | 1 + ...sql => 20241120173924_add_categories_table.sql} | 2 +- migrations/20241120174237_add_positions_table.sql | 2 ++ .../20241120175618_add_users_budgets_table.sql | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) rename migrations/{20241120173924_add_coregories_table.sql => 20241120173924_add_categories_table.sql} (86%) create mode 100644 migrations/20241120175618_add_users_budgets_table.sql diff --git a/migrations/20241120173848_add_budgets_table.sql b/migrations/20241120173848_add_budgets_table.sql index f8bfaf5..cd4d167 100644 --- a/migrations/20241120173848_add_budgets_table.sql +++ b/migrations/20241120173848_add_budgets_table.sql @@ -2,6 +2,7 @@ -- +goose StatementBegin CREATE TABLE IF NOT EXISTS budgets ( id SERIAL PRIMARY KEY, + name TEXT NOT NULL, start_day INT NOT NULL, created_at TIMESTAMP ); diff --git a/migrations/20241120173924_add_coregories_table.sql b/migrations/20241120173924_add_categories_table.sql similarity index 86% rename from migrations/20241120173924_add_coregories_table.sql rename to migrations/20241120173924_add_categories_table.sql index d98ce20..cc085ee 100644 --- a/migrations/20241120173924_add_coregories_table.sql +++ b/migrations/20241120173924_add_categories_table.sql @@ -3,7 +3,7 @@ CREATE TABLE IF NOT EXISTS categories ( id SERIAL PRIMARY KEY, name TEXT NOT NULL, - budget_id INT REFERENCES budgets(id), + budget_id INT REFERENCES budgets(id) ON DELETE CASCADE, favorite BOOLEAN DEFAULT FALSE, monthly_limit INT DEFAULT 0, UNIQUE (budget_id, name), diff --git a/migrations/20241120174237_add_positions_table.sql b/migrations/20241120174237_add_positions_table.sql index cfa7c10..b8efef3 100644 --- a/migrations/20241120174237_add_positions_table.sql +++ b/migrations/20241120174237_add_positions_table.sql @@ -5,6 +5,8 @@ CREATE TABLE IF NOT EXISTS positions ( name TEXT NOT NULL, price INT NOT NULL, amount FLOAT NOT NULL, + budget_id INT REFERENCES budgets(id) ON DELETE CASCADE, + category_id INT REFERENCES categories(id) ON DELETE RESTRICT, created_at TIMESTAMP ); -- +goose StatementEnd diff --git a/migrations/20241120175618_add_users_budgets_table.sql b/migrations/20241120175618_add_users_budgets_table.sql new file mode 100644 index 0000000..e870020 --- /dev/null +++ b/migrations/20241120175618_add_users_budgets_table.sql @@ -0,0 +1,14 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS users_budgets ( + id SERIAL PRIMARY KEY, + user_id INT REFERENCES users(id) ON DELETE CASCADE, + budget_id INT REFERENCES budgets(id) ON DELETE RESTRICT, + created_at TIMESTAMP +); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS users_budgets; +-- +goose StatementEnd