Skip to content

Commit

Permalink
add DB setup statements
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyharrington committed May 21, 2020
1 parent ee41764 commit b62b69c
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions dbCreateStatements-Postgres.txt
Original file line number Diff line number Diff line change
@@ -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');

0 comments on commit b62b69c

Please sign in to comment.