Advertisement
Guest User

Untitled

a guest
May 28th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.47 KB | None | 0 0
  1. create table card_company
  2. (
  3. card_company_id INT NOT NULL AUTO_INCREMENT,
  4. card_company_name_ko VARCHAR(31),
  5. card_company_name_en VARCHAR(31),
  6. card_company_image_path VARCHAR(255),
  7. PRIMARY KEY(card_company_id)
  8. ) DEFAULT CHARSET=utf8;
  9.  
  10. create table card
  11. (
  12. card_id INT NOT NULL AUTO_INCREMENT,
  13. card_company_id INT,
  14.  
  15. selective_card BOOLEAN NOT NULL,
  16. credit_card BOOLEAN NOT NULL,
  17. check_card BOOLEAN NOT NULL,
  18. corporate_card BOOLEAN NOT NULL,
  19. premium_card BOOLEAN NOT NULL,
  20. corp_individual BOOLEAN NOT NULL,
  21. corp_communal BOOLEAN NOT NULL,
  22.  
  23. url VARCHAR(255) NOT NULL,
  24. mobile_url VARCHAR(255) NOT NULL,
  25. image_path VARCHAR(255) NOT NULL,
  26.  
  27. issue_url_desktop VARCHAR(255) NOT NULL,
  28. issue_url_mobile VARCHAR(255) NOT NULL,
  29. issue_phone_number VARCHAR(255) NOT NULL,
  30.  
  31. exportable BOOLEAN NOT NULL,
  32. contracted BOOLEAN NOT NULL,
  33. stopped BOOLEAN NOT NULL,
  34.  
  35. description TEXT,
  36. annual_cost_explanation TEXT,
  37.  
  38. PRIMARY KEY(card_id),
  39. FOREIGN KEY(card_company_id) REFERENCES card_company(card_company_id)
  40. ) DEFAULT CHARSET=utf8;
  41.  
  42. create table card_issue_restriction
  43. (
  44. card_issue_restriction_id INT NOT NULL AUTO_INCREMENT,
  45. description TEXT,
  46.  
  47. PRIMARY KEY(card_issue_restriction_id)
  48. ) DEFAULT CHARSET=utf8;
  49.  
  50. create table card_issue_user_restrictions
  51. (
  52. card_id INT NOT NULL,
  53. card_issue_restriction_id INT NOT NULL,
  54.  
  55. PRIMARY KEY(card_id, card_issue_restriction_id),
  56. FOREIGN KEY(card_id) REFERENCES card(card_id),
  57. FOREIGN KEY(card_issue_restriction_id) REFERENCES card_issue_restriction(card_issue_restriction_id)
  58. ) DEFAULT CHARSET=utf8;
  59.  
  60. create table card_issue
  61. (
  62. card_id INT NOT NULL,
  63.  
  64. issue_id INT NOT NULL AUTO_INCREMENT,
  65. issued_date DATETIME DEFAULT CURRENT_TIMESTAMP,
  66. issued_means ENUM('tel', 'online') NOT NULL,
  67. issued_platform ENUM('app_ios', 'app_android', 'web') NOT NULL,
  68.  
  69. gain_amount INT NOT NULL,
  70. gain_difference INT NOT NULL,
  71.  
  72. PRIMARY KEY(issue_id),
  73. FOREIGN KEY(card_id) REFERENCES card(card_id)
  74. ) DEFAULT CHARSET=utf8;
  75.  
  76. create table card_condition
  77. (
  78. card_condition_id INT NOT NULL AUTO_INCREMENT,
  79. affecting_months TINYINT NOT NULL,
  80. card_condition_criteria VARCHAR(255) NOT NULL,
  81.  
  82. time_unit ENUM('day', 'week', 'year', 'month', 'quarter') NOT NULL,
  83. unit_period INT NOT NULL,
  84.  
  85. PRIMARY KEY(card_condition_id)
  86. ) DEFAULT CHARSET=utf8;
  87.  
  88. create table card_restriction
  89. (
  90. card_restriction_id INT NOT NULL AUTO_INCREMENT,
  91. card_restriction_criteria VARCHAR(255) NOT NULL,
  92.  
  93. card_restriction_domain ENUM('discount', 'point', 'mileage'),
  94. card_restriction_formula ENUM('absolute', 'relative'),
  95.  
  96. restricts_additional_benefits BOOLEAN NOT NULL,
  97.  
  98. time_unit ENUM('day', 'week', 'year', 'month', 'quarter') NOT NULL,
  99. unit_period INT NOT NULL,
  100.  
  101. PRIMARY KEY(card_restriction_id)
  102. ) DEFAULT CHARSET=utf8;
  103.  
  104. create table card_condition_to_restriction
  105. (
  106. card_id INT NOT NULL,
  107. card_condition_to_restriction_id INT NOT NULL AUTO_INCREMENT,
  108. propagation_priority TINYINT,
  109. card_condition_id INT NOT NULL,
  110. card_restriction_id INT NOT NULL,
  111.  
  112. PRIMARY KEY(card_condition_to_restriction_id),
  113. FOREIGN KEY(card_id) REFERENCES card(card_id),
  114. FOREIGN KEY(card_condition_id) REFERENCES card_condition(card_condition_id),
  115. FOREIGN KEY(card_restriction_id) REFERENCES card_restriction(card_restriction_id)
  116. ) DEFAULT CHARSET=utf8;
  117.  
  118. create table card_base_condition
  119. (
  120. card_base_condition_id INT NOT NULL AUTO_INCREMENT,
  121. card_id INT NOT NULL,
  122. card_condition_id INT NOT NULL,
  123.  
  124. PRIMARY KEY(card_base_condition_id),
  125. FOREIGN KEY(card_id) REFERENCES card(card_id),
  126. FOREIGN KEY(card_condition_id) REFERENCES card_condition(card_condition_id)
  127. ) DEFAULT CHARSET=utf8;
  128.  
  129. create table card_base_restriction
  130. (
  131. card_base_restriction_id INT NOT NULL AUTO_INCREMENT,
  132. card_id INT NOT NULL,
  133. card_restriction_id INT NOT NULL,
  134.  
  135. PRIMARY KEY(card_base_restriction_id),
  136. FOREIGN KEY(card_id) REFERENCES card(card_id),
  137. FOREIGN KEY(card_restriction_id) REFERENCES card_restriction(card_restriction_id)
  138. ) DEFAULT CHARSET=utf8;
  139.  
  140. create table card_conditional_restrictions
  141. (
  142. card_id INT NOT NULL,
  143. condition_to_restriction_id INT NOT NULL,
  144.  
  145. PRIMARY KEY(card_id, condition_to_restriction_id),
  146. FOREIGN KEY(card_id) REFERENCES card(card_id),
  147. FOREIGN KEY(condition_to_restriction_id) REFERENCES card_condition_to_restriction(card_condition_to_restriction_id)
  148. ) DEFAULT CHARSET=utf8;
  149.  
  150. create table card_benefit_branch
  151. (
  152. branch_id INT NOT NULL AUTO_INCREMENT,
  153. card_id INT NOT NULL,
  154. branch_description VARCHAR(255),
  155. max_number_of_groups TINYINT,
  156. branch_type ENUM('general', 'mandatory', 'selective', 'optional') NOT NULL,
  157.  
  158. PRIMARY KEY(branch_id),
  159. FOREIGN KEY(card_id) REFERENCES card(card_id),
  160. CHECK((branch_type = 'mandatory' and max_number_of_groups is NULL) or (branch_type = 'optional' or branch_type = 'selective'))
  161. ) DEFAULT CHARSET=utf8;
  162.  
  163. create table store
  164. (
  165. store_id INT NOT NULL AUTO_INCREMENT,
  166. store_name VARCHAR(255),
  167. store_image_path VARCHAR(255),
  168.  
  169. parent_store_id INT,
  170. general_store BOOLEAN NOT NULL DEFAULT FALSE,
  171.  
  172. PRIMARY KEY(store_id),
  173. FOREIGN KEY(parent_store_id) REFERENCES store(store_id)
  174. ) DEFAULT CHARSET=utf8;
  175.  
  176. create table card_benefit_group
  177. (
  178. group_id INT NOT NULL AUTO_INCREMENT,
  179. group_description VARCHAR(255),
  180. additional_annual_cost INT NOT NULL,
  181.  
  182. PRIMARY KEY(group_id)
  183. ) DEFAULT CHARSET=utf8;
  184.  
  185. create table card_benefit
  186. (
  187. benefit_id INT NOT NULL AUTO_INCREMENT,
  188. benefit_title VARCHAR(127) DEFAULT NULL,
  189. benefit_description TEXT,
  190.  
  191. convertible BOOLEAN NOT NULL,
  192. overspent_possible BOOLEAN NOT NULL,
  193. direct BOOLEAN NOT NULL,
  194. charged BOOLEAN NOT NULL,
  195. cashback BOOLEAN NOT NULL,
  196. over_discounted BOOLEAN NOT NULL,
  197. excluded BOOLEAN NOT NULL,
  198.  
  199. card_restriction_applied BOOLEAN NOT NULL,
  200. general_benefit_applied BOOLEAN NOT NULL,
  201. general_benefit_applied_under_condition BOOLEAN NOT NULL,
  202. general_benefit_applied_over_restriction BOOLEAN NOT NULL,
  203.  
  204. benefit_criteria VARCHAR(255),
  205.  
  206. PRIMARY KEY(benefit_id)
  207. ) DEFAULT CHARSET=utf8;
  208.  
  209. create table card_benefit_meta_gain
  210. (
  211. benefit_meta_gain_id INT NOT NULL AUTO_INCREMENT,
  212. benefit_id INT NOT NULL,
  213.  
  214. propagation_priority INT NOT NULL,
  215.  
  216. PRIMARY KEY(benefit_meta_gain_id),
  217. FOREIGN KEY(benefit_id) REFERENCES card_benefit(benefit_id)
  218. ) DEFAULT CHARSET=utf8;
  219.  
  220. create table card_benefit_computation_scheme
  221. (
  222. computation_scheme_id INT NOT NULL AUTO_INCREMENT,
  223. benefit_meta_gain_id INT NOT NULL,
  224.  
  225. computation_type ENUM('constant', 'gas_ratio', 'percentage', 'generic_ratio') NOT NULL,
  226.  
  227. PRIMARY KEY(computation_scheme_id),
  228. FOREIGN KEY(benefit_meta_gain_id) REFERENCES card_benefit_meta_gain(benefit_meta_gain_id)
  229. ) DEFAULT CHARSET=utf8;
  230.  
  231. create table card_benefit_gas_ratio
  232. (
  233. gas_ratio_id INT NOT NULL AUTO_INCREMENT,
  234. computation_scheme_id INT NOT NULL,
  235.  
  236. gas_type ENUM('gasoline', 'diesel', 'kerosene', 'lpg') NOT NULL,
  237. gain_per_liter INT NOT NULL,
  238.  
  239. PRIMARY KEY(gas_ratio_id),
  240. FOREIGN KEY(computation_scheme_id) REFERENCES card_benefit_computation_scheme(computation_scheme_id)
  241. ) DEFAULT CHARSET=utf8;
  242.  
  243. create table card_benefit_generic_ratio
  244. (
  245. generic_ratio_id INT NOT NULL AUTO_INCREMENT,
  246. computation_scheme_id INT NOT NULL,
  247.  
  248. denominator INT NOT NULL,
  249. numerator INT NOT NULL,
  250.  
  251. PRIMARY KEY(generic_ratio_id),
  252. FOREIGN KEY(computation_scheme_id) REFERENCES card_benefit_computation_scheme(computation_scheme_id)
  253. ) DEFAULT CHARSET=utf8;
  254.  
  255. create table card_benefit_percentage
  256. (
  257. percentage_id INT NOT NULL AUTO_INCREMENT,
  258. computation_scheme_id INT NOT NULL,
  259.  
  260. percentange DECIMAL(5, 2) NOT NULL,
  261.  
  262. PRIMARY KEY(percentage_id),
  263. FOREIGN KEY(computation_scheme_id) REFERENCES card_benefit_computation_scheme(computation_scheme_id)
  264. ) DEFAULT CHARSET=utf8;
  265.  
  266. create table card_benefit_constant
  267. (
  268. constant_id INT NOT NULL AUTO_INCREMENT,
  269. computation_scheme_id INT NOT NULL,
  270.  
  271. constant INT NOT NULL,
  272.  
  273. PRIMARY KEY(constant_id),
  274. FOREIGN KEY(computation_scheme_id) REFERENCES card_benefit_computation_scheme(computation_scheme_id)
  275. ) DEFAULT CHARSET=utf8;
  276.  
  277. create table card_benefit_gain_scheme
  278. (
  279. gain_scheme_id INT NOT NULL AUTO_INCREMENT,
  280. benefit_meta_gain_id INT NOT NULL,
  281.  
  282. gain_type ENUM('discount', 'point', 'mileage') NOT NULL,
  283. additional BOOLEAN NOT NULL,
  284.  
  285. point_mileage_code VARCHAR(127),
  286.  
  287. PRIMARY KEY(gain_scheme_id),
  288. FOREIGN KEY(benefit_meta_gain_id) REFERENCES card_benefit_meta_gain(benefit_meta_gain_id)
  289. ) DEFAULT CHARSET=utf8;
  290.  
  291. create table card_benefit_condition
  292. (
  293. benefit_condition_id INT NOT NULL AUTO_INCREMENT,
  294. benefit_id INT NOT NULL,
  295. affecting_months TINYINT,
  296. condition_criteria VARCHAR(255) NOT NULL,
  297.  
  298. time_unit ENUM('day', 'week', 'year', 'month', 'quarter') NOT NULL,
  299. unit_period INT NOT NULL,
  300.  
  301. PRIMARY KEY(benefit_condition_id),
  302. FOREIGN KEY(benefit_id) REFERENCES card_benefit(benefit_id)
  303. ) DEFAULT CHARSET=utf8;
  304.  
  305. create table card_payment_condition
  306. (
  307. payment_condition_id INT NOT NULL AUTO_INCREMENT,
  308. payment_threshold_value INT NOT NULL,
  309. benefit_id INT NOT NULL,
  310. PRIMARY KEY(payment_condition_id),
  311. FOREIGN KEY(benefit_id) REFERENCES card_benefit(benefit_id)
  312. ) DEFAULT CHARSET=utf8;
  313.  
  314. create table card_condition_affecting_stores
  315. (
  316. benefit_condition_id INT NOT NULL,
  317. store_id INT NOT NULL,
  318. PRIMARY KEY(benefit_condition_id, store_id),
  319. FOREIGN KEY(benefit_condition_id) REFERENCES card_benefit_condition(benefit_condition_id)
  320. ) DEFAULT CHARSET=utf8;
  321.  
  322. create table card_benefit_restriction
  323. (
  324. benefit_restriction_id INT NOT NULL AUTO_INCREMENT,
  325. benefit_id INT NOT NULL,
  326. restriction_criteria VARCHAR(255) NOT NULL,
  327. restriction_months TINYINT,
  328. restriction_type ENUM('amount', 'time', 'discount', 'point', 'number', 'mile') NOT NULL,
  329. applied_complementarily BOOLEAN NOT NULL DEFAULT FALSE,
  330.  
  331. restricts_additional_benefits BOOLEAN NOT NULL,
  332.  
  333. time_unit ENUM('day', 'week', 'year', 'month', 'quarter') NOT NULL,
  334. unit_period INT NOT NULL,
  335.  
  336. PRIMARY KEY(benefit_restriction_id),
  337. FOREIGN KEY(benefit_id) REFERENCES card_benefit(benefit_id)
  338. ) DEFAULT CHARSET=utf8;
  339.  
  340. create table card_payment_restriction
  341. (
  342. payment_restriction_id INT NOT NULL AUTO_INCREMENT,
  343. benefit_id INT NOT NULL,
  344. payment_restricted_value INT NOT NULL,
  345. PRIMARY KEY(payment_restriction_id),
  346. FOREIGN KEY(benefit_id) REFERENCES card_benefit(benefit_id)
  347. ) DEFAULT CHARSET=utf8;
  348.  
  349. create table card_restricted_benefits
  350. (
  351. benefit_restriction_id INT NOT NULL,
  352. restricted_benefit_id INT NOT NULL,
  353. PRIMARY KEY(benefit_restriction_id, restricted_benefit_id),
  354. FOREIGN KEY(benefit_restriction_id) REFERENCES card_benefit_restriction(benefit_restriction_id),
  355. FOREIGN KEY(restricted_benefit_id) REFERENCES card_benefit(benefit_id)
  356. ) DEFAULT CHARSET=utf8;
  357.  
  358. create table card_restrictive_stores
  359. (
  360. benefit_restriction_id INT NOT NULL,
  361. restrictive_store_id INT NOT NULL,
  362. PRIMARY KEY(benefit_restriction_id, restrictive_store_id),
  363. FOREIGN KEY(benefit_restriction_id) REFERENCES card_benefit_restriction(benefit_restriction_id),
  364. FOREIGN KEY(restrictive_store_id) REFERENCES store(store_id)
  365. ) DEFAULT CHARSET=utf8;
  366.  
  367. create table card_benefit_branch_group
  368. (
  369. branch_id INT NOT NULL,
  370. group_id INT NOT NULL,
  371. PRIMARY KEY(branch_id, group_id),
  372. FOREIGN KEY(branch_id) REFERENCES card_benefit_branch(branch_id),
  373. FOREIGN KEY(group_id) REFERENCES card_benefit_group(group_id)
  374. ) DEFAULT CHARSET=utf8;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement