From b62b69c85b003e24742f6257174f8f051674bd8e Mon Sep 17 00:00:00 2001 From: Eddy Harrington Date: Thu, 21 May 2020 11:32:22 -0700 Subject: [PATCH] add DB setup statements --- dbCreateStatements-Postgres.txt | 77 +++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 dbCreateStatements-Postgres.txt diff --git a/dbCreateStatements-Postgres.txt b/dbCreateStatements-Postgres.txt new file mode 100644 index 0000000..b860c3f --- /dev/null +++ b/dbCreateStatements-Postgres.txt @@ -0,0 +1,77 @@ +CREATE TABLE IF NOT EXISTS users ( + id serial PRIMARY KEY, + username TEXT NOT NULL, + hash TEXT NOT NULL, + income REAL NOT NULL DEFAULT 60000.00, + registerDate TEXT NOT NULL, + lastLogin TEXT NOT NULL +); + +CREATE TABLE IF NOT EXISTS budgets ( + id serial PRIMARY KEY, + name TEXT NOT NULL, + amount REAL, + user_id INTEGER NOT NULL, + CONSTRAINT budgets_user_id_fkey FOREIGN KEY (user_id) + REFERENCES users (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION +); + +CREATE TABLE IF NOT EXISTS categories ( + id serial PRIMARY KEY, + name TEXT NOT NULL +); + +CREATE TABLE IF NOT EXISTS userCategories ( + category_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + CONSTRAINT userCategories_category_id_fkey FOREIGN KEY (category_id) + REFERENCES categories (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT userCategories_user_id_fkey FOREIGN KEY (user_id) + REFERENCES users (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION +); + +CREATE TABLE IF NOT EXISTS budgetCategories ( + budgets_id INTEGER NOT NULL, + category_id INTEGER NOT NULL, + amount REAL NOT NULL DEFAULT 0, + CONSTRAINT budgetCategories_budgets_id_fkey FOREIGN KEY (budgets_id) + REFERENCES budgets(id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT budgetCategories_category_id_fkey FOREIGN KEY (category_id) + REFERENCES categories (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION +); + +CREATE TABLE IF NOT EXISTS payers ( + user_id INTEGER NOT NULL, + name TEXT NOT NULL, + CONSTRAINT payers_user_id_fkey FOREIGN KEY (user_id) + REFERENCES users (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION +); + +CREATE TABLE IF NOT EXISTS expenses ( + id serial PRIMARY KEY, + description TEXT NOT NULL, + category TEXT NOT NULL, + expenseDate TEXT NOT NULL, + amount REAL NOT NULL, + payer TEXT NOT NULL, + submitTime TEXT NOT NULL, + user_id INTEGER, + CONSTRAINT budgets_user_id_fkey FOREIGN KEY (user_id) + REFERENCES users (id) MATCH SIMPLE + ON UPDATE NO ACTION ON DELETE NO ACTION +); + +INSERT INTO categories(name) VALUES ('Groceries'); +INSERT INTO categories(name) VALUES ('Rent'); +INSERT INTO categories(name) VALUES ('Utilities'); +INSERT INTO categories(name) VALUES ('Dining Out'); +INSERT INTO categories(name) VALUES ('Shopping'); +INSERT INTO categories(name) VALUES ('Travel'); +INSERT INTO categories(name) VALUES ('Entertainment'); +INSERT INTO categories(name) VALUES ('Other'); \ No newline at end of file