Преглед на файлове

Setup database tables

master
Immanuel Onyeka преди 2 години
родител
ревизия
e09de1c690
променени са 4 файла, в които са добавени 124 реда и са изтрити 0 реда
  1. +1
    -0
      .gitignore
  2. +114
    -0
      migrations/0_29092022_create_main_tables.sql
  3. +2
    -0
      migrations/reset.sql
  4. +7
    -0
      migrations/seed.sql

+ 1
- 0
.gitignore Целия файл

@@ -2,3 +2,4 @@ node_modules/
*.json
skouter
*.sw[poqa]
.env

+ 114
- 0
migrations/0_29092022_create_main_tables.sql Целия файл

@@ -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,
);

+ 2
- 0
migrations/reset.sql Целия файл

@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS license;
DROP TABLE IF EXISTS users

+ 7
- 0
migrations/seed.sql Целия файл

@@ -0,0 +1,7 @@
INSERT INTO user
(firstName, lastName, nmls)
VALUES
('Blue Train', 'John Coltrane', 56.99),
('Giant Steps', 'John Coltrane', 63.99),
('Jeru', 'Gerry Mulligan', 17.99),
('Sarah Vaughan', 'Sarah Vaughan', 34.98);

Loading…
Отказ
Запис