|
|
@@ -0,0 +1,114 @@ |
|
|
|
/* Precision for all money amounts assumes cents are excluded. */ |
|
|
|
|
|
|
|
CREATE TABLE user ( |
|
|
|
id INT AUTO_INCREMENT NOT NULL, |
|
|
|
email VARCHAR(40) NOT NULL, |
|
|
|
first_name VARCHAR(30) NOT NULL, |
|
|
|
last_name VARCHAR(30) NOT NULL, |
|
|
|
password CHAR(64) NOT NULL, |
|
|
|
branch_id INT, |
|
|
|
/* The password should be a SHA256 hash in hex format. It's length doesn't |
|
|
|
* vary */ |
|
|
|
country ENUM('Canada', 'USA'), |
|
|
|
title ENUM('Loan Officer', |
|
|
|
'Branch Manager', |
|
|
|
'Mortgage Broker', |
|
|
|
'Other'), |
|
|
|
status ENUM('Trial', |
|
|
|
'Free', |
|
|
|
'Subscribed', |
|
|
|
'Branch Subscribed'), |
|
|
|
PRIMARY KEY (`id`), |
|
|
|
FOREIGN KEY (branch_id) REFERENCES branch(id) |
|
|
|
ON DELETE SET NULL |
|
|
|
); |
|
|
|
|
|
|
|
CREATE TABLE license ( |
|
|
|
id INT AUTO_INCREMENT NOT NULL, |
|
|
|
user_id INT NOT NULL, |
|
|
|
type ENUM('NMLS', 'FSRA'), |
|
|
|
number VARCHAR(40) NOT NULL, |
|
|
|
PRIMARY KEY (`id`), |
|
|
|
FOREIGN KEY (user_id) REFERENCES user(id) |
|
|
|
ON DELETE CASCADE |
|
|
|
ON UPDATE RESTRICT |
|
|
|
); |
|
|
|
|
|
|
|
CREATE TABLE branch ( |
|
|
|
id INT AUTO_INCREMENT NOT NULL, |
|
|
|
type ENUM('NMLS', 'FSRA'), |
|
|
|
num VARCHAR(40) NOT NULL, |
|
|
|
PRIMARY KEY (`id`), |
|
|
|
); |
|
|
|
|
|
|
|
CREATE TABLE comparison ( |
|
|
|
id INT AUTO_INCREMENT NOT NULL, |
|
|
|
PRIMARY KEY (`id`), |
|
|
|
); |
|
|
|
|
|
|
|
/* Officers or managers may need to create new loan types with custom settings. |
|
|
|
* Types with branch_id and user_id values of null will be general cases. */ |
|
|
|
CREATE TABLE loan_type ( |
|
|
|
id INT AUTO_INCREMENT NOT NULL, |
|
|
|
branch_id INT, |
|
|
|
user_id INT, |
|
|
|
name VARCHAR(30), |
|
|
|
FOREIGN KEY (branch_id) REFERENCES branch(id), |
|
|
|
FOREIGN KEY (user_id) REFERENCES user(id), |
|
|
|
PRIMARY KEY (`id`) |
|
|
|
); |
|
|
|
|
|
|
|
CREATE TABLE estimate ( |
|
|
|
id INT AUTO_INCREMENT NOT NULL, |
|
|
|
user_id INT NOT NULL, |
|
|
|
comparison_id INT, |
|
|
|
transaction ENUM('Purchase', 'Refinance'), |
|
|
|
loan_type_id INT NOT NULL, |
|
|
|
loan_amount INT NOT NULL, |
|
|
|
price INT NOT NULL, |
|
|
|
property ENUM('Single Family Detached', |
|
|
|
'Single Family Attached', |
|
|
|
'Condominium Lo-rise', |
|
|
|
'Condominium Hi-rise'), |
|
|
|
pud BOOLEAN, /* Property under development */ |
|
|
|
term INT, /* In months */ |
|
|
|
interest INT, /* Per year, precise to 2 decimals */ |
|
|
|
hoi INT, /* Hazard insurance annual payments */ |
|
|
|
mi_name VARCHAR(50), /* Mortgage insurance title shown in menu */ |
|
|
|
mi_amount INT, /* Mortgage insurance amount */ |
|
|
|
lender VARCHAR(30), |
|
|
|
PRIMARY KEY (`id`), |
|
|
|
FOREIGN KEY (loan_type_id) REFERENCES loan_type(id) |
|
|
|
ON UPDATE RESTRICT, |
|
|
|
FOREIGN KEY (comparison_id) REFERENCES comparison(id) |
|
|
|
ON DELETE CASCADE |
|
|
|
ON UPDATE RESTRICT |
|
|
|
); |
|
|
|
|
|
|
|
CREATE TABLE borrower ( |
|
|
|
id INT AUTO_INCREMENT NOT NULL, |
|
|
|
estimate_id INT, |
|
|
|
credit_score SMALLINT, |
|
|
|
monthly_income INT, |
|
|
|
num TINYINT, /* Number of people borrowing. */ |
|
|
|
PRIMARY KEY (`id`) |
|
|
|
FOREIGN KEY (estimate_id) REFERENCES estimate(id) |
|
|
|
); |
|
|
|
|
|
|
|
/* template = true fees are saved for users or branches. If template or default |
|
|
|
* are true, estimate_id should be null. */ |
|
|
|
CREATE TABLE fee ( |
|
|
|
id INT AUTO_INCREMENT NOT NULL, |
|
|
|
user_id INT NOT NULL, |
|
|
|
user_id INT NOT NULL, |
|
|
|
estimate_id INT, |
|
|
|
type ENUM('Goverment', 'Title', 'Other'), |
|
|
|
notes VARCHAR(255), |
|
|
|
name VARCHAR(30), |
|
|
|
category VARCHAR(60), /* Group heading shown in report */ |
|
|
|
template BOOLEAN, /* If fee should appear reusable through a menu */ |
|
|
|
default BOOLEAN, /* If fee should be automatically applied */ |
|
|
|
PRIMARY KEY (`id`), |
|
|
|
FOREIGN KEY (user_id) REFERENCES user(id), |
|
|
|
FOREIGN KEY (estimate_id) REFERENCES estimate(id) ON DELETE CASCADE, |
|
|
|
); |