Skouter mortgage estimates. Web application with view written in PHP and Vue, but controller and models in Go.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

132 рядки
3.6 KiB

  1. /* Precision for all money amounts assumes cents are excluded. */
  2. CREATE TABLE comparison (
  3. id INT AUTO_INCREMENT,
  4. PRIMARY KEY (id)
  5. );
  6. CREATE TABLE branch (
  7. id INT AUTO_INCREMENT,
  8. type ENUM('NMLS', 'FSRA'),
  9. num VARCHAR(40) NOT NULL,
  10. PRIMARY KEY (id)
  11. );
  12. CREATE TABLE user (
  13. id INT AUTO_INCREMENT,
  14. email VARCHAR(40) NOT NULL,
  15. first_name VARCHAR(30) NOT NULL,
  16. last_name VARCHAR(30) NOT NULL,
  17. password CHAR(64) NOT NULL,
  18. verified BOOLEAN,
  19. branch_id INT,
  20. /* The password should be a SHA256 hash in hex format. It's length doesn't
  21. * vary */
  22. country ENUM('Canada', 'USA'),
  23. title ENUM('Loan Officer',
  24. 'Branch Manager',
  25. 'Mortgage Broker',
  26. 'Other'),
  27. status ENUM('Trial',
  28. 'Free',
  29. 'Subscribed',
  30. 'Branch Subscribed'),
  31. PRIMARY KEY (`id`),
  32. FOREIGN KEY (branch_id) REFERENCES branch(id)
  33. ON DELETE SET NULL
  34. );
  35. CREATE TABLE license (
  36. id INT AUTO_INCREMENT,
  37. user_id INT NOT NULL,
  38. type ENUM('NMLS', 'FSRA'),
  39. num VARCHAR(40) NOT NULL,
  40. PRIMARY KEY (`id`),
  41. FOREIGN KEY (user_id) REFERENCES user(id)
  42. ON DELETE CASCADE
  43. ON UPDATE RESTRICT
  44. );
  45. /* Officers or managers may need to create new loan types with custom settings.
  46. * Types with branch_id and user_id values of null will be general cases. */
  47. CREATE TABLE loan_type (
  48. id INT AUTO_INCREMENT,
  49. branch_id INT,
  50. user_id INT,
  51. name VARCHAR(30),
  52. FOREIGN KEY (branch_id) REFERENCES branch(id),
  53. FOREIGN KEY (user_id) REFERENCES user(id),
  54. PRIMARY KEY (`id`)
  55. );
  56. CREATE TABLE borrower (
  57. id INT AUTO_INCREMENT,
  58. credit_score SMALLINT,
  59. monthly_income INT,
  60. num TINYINT, /* Number of people borrowing. */
  61. PRIMARY KEY (`id`)
  62. );
  63. CREATE TABLE estimate (
  64. id INT AUTO_INCREMENT,
  65. user_id INT NOT NULL,
  66. borrower_id INT NOT NULL,
  67. comparison_id INT,
  68. transaction ENUM('Purchase', 'Refinance'),
  69. loan_type_id INT NOT NULL,
  70. loan_amount INT NOT NULL,
  71. price INT NOT NULL,
  72. property ENUM('Single Family Detached',
  73. 'Single Family Attached',
  74. 'Condominium Lo-rise',
  75. 'Condominium Hi-rise'),
  76. pud BOOLEAN, /* Property under development */
  77. term INT, /* In months */
  78. interest INT, /* Per year, precise to 2 decimals */
  79. hoi INT, /* Hazard insurance annual payments */
  80. mi_name VARCHAR(50), /* Mortgage insurance title shown in menu */
  81. mi_amount INT, /* Mortgage insurance amount */
  82. lender VARCHAR(30),
  83. PRIMARY KEY (`id`),
  84. FOREIGN KEY (loan_type_id) REFERENCES loan_type(id)
  85. ON UPDATE RESTRICT,
  86. FOREIGN KEY (comparison_id) REFERENCES comparison(id)
  87. ON DELETE CASCADE
  88. ON UPDATE RESTRICT,
  89. FOREIGN KEY (borrower_id) REFERENCES borrower(id)
  90. );
  91. /* template = true fees are saved for users or branches. If template or default
  92. * are true, estimate_id should be null. */
  93. CREATE TABLE fee (
  94. id INT AUTO_INCREMENT NOT NULL,
  95. estimate_id INT,
  96. amount INT NOT NULL,
  97. type ENUM('Goverment', 'Title', 'Other'),
  98. notes VARCHAR(255),
  99. name VARCHAR(30),
  100. /* Group heading shown in report */
  101. category VARCHAR(60),
  102. PRIMARY KEY (`id`),
  103. FOREIGN KEY (estimate_id) REFERENCES estimate(id)
  104. );
  105. /* Templates to be reused by users or branches. Either user_id or branch_id must
  106. * be non-null. */
  107. CREATE TABLE fee_template (
  108. id INT AUTO_INCREMENT,
  109. user_id INT,
  110. branch_id INT,
  111. amount INT NOT NULL,
  112. type ENUM('Goverment', 'Title', 'Other'),
  113. notes VARCHAR(255),
  114. name VARCHAR(30),
  115. /* Group heading shown in report */
  116. category VARCHAR(60),
  117. auto BOOLEAN,
  118. /* If fee should be automatically applied */
  119. PRIMARY KEY (`id`),
  120. FOREIGN KEY (user_id) REFERENCES user(id),
  121. FOREIGN KEY (branch_id) REFERENCES branch(id)
  122. );