瀏覽代碼

Fix table setup errors

master
Immanuel Onyeka 2 年之前
父節點
當前提交
53277258c9
共有 2 個文件被更改,包括 57 次插入35 次删除
  1. +50
    -34
      migrations/0_29092022_create_main_tables.sql
  2. +7
    -1
      migrations/reset.sql

+ 50
- 34
migrations/0_29092022_create_main_tables.sql 查看文件

@@ -1,7 +1,19 @@
/* Precision for all money amounts assumes cents are excluded. */

CREATE TABLE comparison (
id INT AUTO_INCREMENT,
PRIMARY KEY (id)
);

CREATE TABLE branch (
id INT AUTO_INCREMENT,
type ENUM('NMLS', 'FSRA'),
num VARCHAR(40) NOT NULL,
PRIMARY KEY (id)
);

CREATE TABLE user (
id INT AUTO_INCREMENT NOT NULL,
id INT AUTO_INCREMENT,
email VARCHAR(40) NOT NULL,
first_name VARCHAR(30) NOT NULL,
last_name VARCHAR(30) NOT NULL,
@@ -24,32 +36,20 @@ CREATE TABLE user (
);

CREATE TABLE license (
id INT AUTO_INCREMENT NOT NULL,
id INT AUTO_INCREMENT,
user_id INT NOT NULL,
type ENUM('NMLS', 'FSRA'),
number VARCHAR(40) NOT NULL,
num 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,
id INT AUTO_INCREMENT,
branch_id INT,
user_id INT,
name VARCHAR(30),
@@ -58,9 +58,18 @@ CREATE TABLE loan_type (
PRIMARY KEY (`id`)
);

CREATE TABLE borrower (
id INT AUTO_INCREMENT,
credit_score SMALLINT,
monthly_income INT,
num TINYINT, /* Number of people borrowing. */
PRIMARY KEY (`id`)
);

CREATE TABLE estimate (
id INT AUTO_INCREMENT NOT NULL,
id INT AUTO_INCREMENT,
user_id INT NOT NULL,
borrower_id INT NOT NULL,
comparison_id INT,
transaction ENUM('Purchase', 'Refinance'),
loan_type_id INT NOT NULL,
@@ -82,33 +91,40 @@ CREATE TABLE estimate (
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)
ON UPDATE RESTRICT,
FOREIGN KEY (borrower_id) REFERENCES borrower(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,
amount INT NOT NULL,
type ENUM('Goverment', 'Title', 'Other'),
notes VARCHAR(255),
name VARCHAR(30),
/* Group heading shown in report */
category VARCHAR(60),
PRIMARY KEY (`id`),
FOREIGN KEY (estimate_id) REFERENCES estimate(id)
);

/* Templates to be reused by users or branches. Either user_id or branch_id must
* be non-null. */
CREATE TABLE fee_template (
id INT AUTO_INCREMENT,
user_id INT,
branch_id INT,
amount INT NOT NULL,
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 */
/* Group heading shown in report */
category VARCHAR(60),
auto 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,
FOREIGN KEY (branch_id) REFERENCES branch(id)
);

+ 7
- 1
migrations/reset.sql 查看文件

@@ -1,2 +1,8 @@
DROP TABLE IF EXISTS fee;
DROP TABLE IF EXISTS estimate;
DROP TABLE IF EXISTS borrower;
DROP TABLE IF EXISTS loan_type;
DROP TABLE IF EXISTS license;
DROP TABLE IF EXISTS users
DROP TABLE IF EXISTS user;
DROP TABLE IF EXISTS branch;
DROP TABLE IF EXISTS comparison;

Loading…
取消
儲存