Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

187 satır
5.3 KiB

  1. /* Precision for all money amounts assumes cents are excluded. */
  2. CREATE TABLE address (
  3. id INT AUTO_INCREMENT,
  4. full_address VARCHAR(200) NOT NULL,
  5. street VARCHAR(40) NOT NULL,
  6. city VARCHAR(40) NOT NULL,
  7. region VARCHAR(40) NOT NULL,
  8. country VARCHAR(40) NOT NULL,
  9. zip VARCHAR(10) NOT NULL,
  10. PRIMARY KEY (`id`)
  11. );
  12. CREATE TABLE branch (
  13. id INT AUTO_INCREMENT,
  14. type ENUM('NMLS', 'FSRA') NOT NULL,
  15. letterhead BLOB(102400) NOT NULL DEFAULT 0,
  16. num VARCHAR(40) NOT NULL,
  17. phone VARCHAR(20) NOT NULL,
  18. address INT NOT NULL,
  19. PRIMARY KEY (id),
  20. FOREIGN KEY (address) REFERENCES address(id)
  21. );
  22. CREATE TABLE user (
  23. id INT AUTO_INCREMENT,
  24. email VARCHAR(40) UNIQUE NOT NULL,
  25. first_name VARCHAR(30) NOT NULL,
  26. last_name VARCHAR(30) NOT NULL,
  27. phone VARCHAR(20) NOT NULL,
  28. address INT NOT NULL,
  29. password CHAR(64) NOT NULL,
  30. verified BOOLEAN,
  31. branch_id INT NULL,
  32. avatar BLOB(102400) NOT NULL DEFAULT 0,
  33. letterhead BLOB(102400) NOT NULL DEFAULT 0,
  34. /* The password should be a SHA256 hash in hex format. It's length doesn't
  35. * vary */
  36. country ENUM('Canada', 'USA'),
  37. title ENUM('Loan Officer',
  38. 'Branch Manager',
  39. 'Mortgage Broker',
  40. 'Other'),
  41. status ENUM('Trial',
  42. 'Free',
  43. 'Subscribed',
  44. 'Branch',
  45. 'Admin'),
  46. role ENUM('User', 'Manager', 'Admin') NOT NULL,
  47. PRIMARY KEY (`id`),
  48. FOREIGN KEY (branch_id) REFERENCES branch(id),
  49. FOREIGN KEY (address) REFERENCES address(id)
  50. );
  51. CREATE TABLE license (
  52. id INT AUTO_INCREMENT,
  53. user_id INT NOT NULL,
  54. type ENUM('NMLS', 'FSRA'),
  55. num VARCHAR(40) NOT NULL,
  56. PRIMARY KEY (`id`),
  57. FOREIGN KEY (user_id) REFERENCES user(id)
  58. ON DELETE CASCADE
  59. ON UPDATE RESTRICT
  60. );
  61. /* Officers or managers may need to create new loan types with custom settings.
  62. * Types with branch_id and user_id values of 0 will be general cases. */
  63. CREATE TABLE loan_type (
  64. id INT AUTO_INCREMENT,
  65. branch_id INT NOT NULL,
  66. user_id INT NOT NULL,
  67. name VARCHAR(30) UNIQUE NOT NULL,
  68. /* FOREIGN KEY (branch_id) REFERENCES branch(id), */
  69. /* FOREIGN KEY (user_id) REFERENCES user(id), */
  70. PRIMARY KEY (`id`)
  71. );
  72. CREATE TABLE borrower (
  73. id INT AUTO_INCREMENT,
  74. credit_score SMALLINT NOT NULL,
  75. monthly_income INT NOT NULL,
  76. num TINYINT NOT NULL, /* Number of people borrowing. */
  77. PRIMARY KEY (`id`)
  78. );
  79. CREATE TABLE estimate (
  80. id INT AUTO_INCREMENT,
  81. user_id INT NOT NULL,
  82. borrower_id INT NOT NULL,
  83. transaction ENUM('Purchase', 'Refinance'),
  84. price INT NOT NULL,
  85. property ENUM('Single Detached',
  86. 'Single Attached',
  87. 'Condo Lo-rise',
  88. 'Condo Hi-rise'),
  89. occupancy ENUM('Primary', 'Secondary', 'Investment'),
  90. zip VARCHAR(10),
  91. pud BOOLEAN, /* Property under development */
  92. PRIMARY KEY (`id`),
  93. FOREIGN KEY (borrower_id) REFERENCES borrower(id)
  94. );
  95. CREATE TABLE loan (
  96. id INT AUTO_INCREMENT,
  97. estimate_id INT NOT NULL,
  98. type_id INT NOT NULL,
  99. amount INT NOT NULL,
  100. term INT, /* In years */
  101. interest FLOAT(5, 2) DEFAULT 0,
  102. ltv FLOAT(5, 2) DEFAULT 0,
  103. dti FLOAT(5, 2) DEFAULT 1,
  104. hoi INT DEFAULT 0, /* Home owner's insurance annual payments */
  105. hazard INT DEFAULT 0, /* Hazard insurance annual payments */
  106. tax INT DEFAULT 0, /* Real estate taxes */
  107. name VARCHAR(30) DEFAULT '',
  108. PRIMARY KEY (`id`),
  109. FOREIGN KEY (estimate_id) REFERENCES estimate(id),
  110. FOREIGN KEY (type_id) REFERENCES loan_type(id)
  111. ON UPDATE RESTRICT
  112. );
  113. CREATE TABLE mi (
  114. id INT AUTO_INCREMENT,
  115. loan_id INT,
  116. type VARCHAR(10) NOT NULL DEFAULT "",
  117. label VARCHAR(30) NOT NULL DEFAULT "",
  118. lender VARCHAR(20) NOT NULL DEFAULT "",
  119. rate INT DEFAULT 0,
  120. premium INT DEFAULT 0,
  121. upfront INT DEFAULT 0,
  122. five_year_total INT DEFAULT 0,
  123. initial_premium INT DEFAULT 0,
  124. initial_rate INT DEFAULT 0,
  125. initial_amount INT DEFAULT 0,
  126. PRIMARY KEY (`id`),
  127. FOREIGN KEY (loan_id) REFERENCES loan(id)
  128. );
  129. /* template = true fees are saved for users or branches. If template or default
  130. * are true, estimate_id should be null. */
  131. CREATE TABLE fee (
  132. id INT AUTO_INCREMENT NOT NULL,
  133. loan_id INT,
  134. amount INT NOT NULL,
  135. perc SMALLINT, /* Percentage of sale price instead of amount */
  136. type ENUM('Government', 'Title', 'Required', 'Lender', 'Other'),
  137. notes VARCHAR(255),
  138. name VARCHAR(30),
  139. /* Group heading shown in report */
  140. category VARCHAR(60),
  141. PRIMARY KEY (`id`),
  142. FOREIGN KEY (loan_id) REFERENCES loan(id)
  143. );
  144. /* Templates to be reused by users or branches. Either user_id or branch_id must
  145. * be non-null.*/
  146. CREATE TABLE fee_template (
  147. id INT AUTO_INCREMENT,
  148. user_id INT NOT NULL,
  149. branch_id INT,
  150. amount INT NOT NULL,
  151. perc SMALLINT NOT NULL,
  152. /* Percentage of sale price instead of amount */
  153. type ENUM('Government', 'Title', 'Required', 'Lender', 'Other'),
  154. notes VARCHAR(255) NOT NULL,
  155. name VARCHAR(30) NOT NULL,
  156. /* Group heading shown in report */
  157. category VARCHAR(60) NOT NULL DEFAULT "",
  158. auto BOOLEAN NOT NULL,
  159. /* If fee should be automatically applied */
  160. PRIMARY KEY (`id`),
  161. FOREIGN KEY (user_id) REFERENCES user(id),
  162. FOREIGN KEY (branch_id) REFERENCES branch(id)
  163. );
  164. CREATE TABLE estimate_result (
  165. id INT AUTO_INCREMENT,
  166. loan_id INT UNIQUE NOT NULL,
  167. loan_payment INT NOT NULL,
  168. total_monthly INT NOT NULL,
  169. total_fees INT NOT NULL,
  170. total_credits INT NOT NULL,
  171. cash_to_close INT NOT NULL,
  172. PRIMARY KEY (`id`),
  173. FOREIGN KEY (loan_id) REFERENCES loan(id)
  174. );