Single-sign-on and self-serve account management. https://netsyms.biz/apps/accounthub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

database.sql 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. -- MySQL Script generated by MySQL Workbench
  2. -- Mon 21 May 2018 04:05:27 PM MDT
  3. -- Model: New Model Version: 1.0
  4. -- MySQL Workbench Forward Engineering
  5. SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
  6. SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
  7. SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
  8. -- -----------------------------------------------------
  9. -- Schema accounthub
  10. -- -----------------------------------------------------
  11. -- -----------------------------------------------------
  12. -- Schema accounthub
  13. -- -----------------------------------------------------
  14. CREATE SCHEMA IF NOT EXISTS `accounthub` DEFAULT CHARACTER SET utf8 ;
  15. USE `accounthub` ;
  16. -- -----------------------------------------------------
  17. -- Table `accounthub`.`acctstatus`
  18. -- -----------------------------------------------------
  19. CREATE TABLE IF NOT EXISTS `accounthub`.`acctstatus` (
  20. `statusid` INT NOT NULL AUTO_INCREMENT,
  21. `statuscode` VARCHAR(45) NOT NULL,
  22. PRIMARY KEY (`statusid`),
  23. UNIQUE INDEX `statusid_UNIQUE` (`statusid` ASC),
  24. UNIQUE INDEX `statuscode_UNIQUE` (`statuscode` ASC))
  25. ENGINE = InnoDB;
  26. -- -----------------------------------------------------
  27. -- Table `accounthub`.`accttypes`
  28. -- -----------------------------------------------------
  29. CREATE TABLE IF NOT EXISTS `accounthub`.`accttypes` (
  30. `typeid` INT NOT NULL AUTO_INCREMENT,
  31. `typecode` VARCHAR(45) NOT NULL,
  32. PRIMARY KEY (`typeid`),
  33. UNIQUE INDEX `typeid_UNIQUE` (`typeid` ASC),
  34. UNIQUE INDEX `typecode_UNIQUE` (`typecode` ASC))
  35. ENGINE = InnoDB;
  36. -- -----------------------------------------------------
  37. -- Table `accounthub`.`accounts`
  38. -- -----------------------------------------------------
  39. CREATE TABLE IF NOT EXISTS `accounthub`.`accounts` (
  40. `uid` INT NOT NULL AUTO_INCREMENT,
  41. `username` VARCHAR(190) NOT NULL,
  42. `password` VARCHAR(255) NULL,
  43. `realname` VARCHAR(255) NOT NULL,
  44. `email` VARCHAR(255) NULL DEFAULT 'NOEMAIL@EXAMPLE.COM',
  45. `authsecret` VARCHAR(100) NULL,
  46. `pin` VARCHAR(10) NULL,
  47. `phone1` VARCHAR(45) NOT NULL,
  48. `phone2` VARCHAR(45) NOT NULL,
  49. `acctstatus` INT NOT NULL DEFAULT 0,
  50. `accttype` INT NOT NULL,
  51. `deleted` TINYINT(1) NOT NULL DEFAULT 0,
  52. PRIMARY KEY (`uid`, `username`),
  53. UNIQUE INDEX `userid_UNIQUE` (`uid` ASC),
  54. UNIQUE INDEX `username_UNIQUE` (`username` ASC),
  55. INDEX `fk_accounts_acctstatus_idx` (`acctstatus` ASC),
  56. INDEX `email_index` (`email` ASC),
  57. INDEX `fk_accounts_accttypes1_idx` (`accttype` ASC),
  58. CONSTRAINT `fk_accounts_acctstatus`
  59. FOREIGN KEY (`acctstatus`)
  60. REFERENCES `accounthub`.`acctstatus` (`statusid`)
  61. ON DELETE NO ACTION
  62. ON UPDATE NO ACTION,
  63. CONSTRAINT `fk_accounts_accttypes1`
  64. FOREIGN KEY (`accttype`)
  65. REFERENCES `accounthub`.`accttypes` (`typeid`)
  66. ON DELETE NO ACTION
  67. ON UPDATE NO ACTION)
  68. ENGINE = InnoDB;
  69. -- -----------------------------------------------------
  70. -- Table `accounthub`.`apps`
  71. -- -----------------------------------------------------
  72. CREATE TABLE IF NOT EXISTS `accounthub`.`apps` (
  73. `appid` INT NOT NULL AUTO_INCREMENT,
  74. `appname` VARCHAR(45) NULL,
  75. `appcode` VARCHAR(45) NULL,
  76. PRIMARY KEY (`appid`),
  77. UNIQUE INDEX `appid_UNIQUE` (`appid` ASC))
  78. ENGINE = InnoDB;
  79. -- -----------------------------------------------------
  80. -- Table `accounthub`.`available_apps`
  81. -- -----------------------------------------------------
  82. CREATE TABLE IF NOT EXISTS `accounthub`.`available_apps` (
  83. `appid` INT NOT NULL,
  84. `uid` INT NOT NULL,
  85. PRIMARY KEY (`appid`, `uid`),
  86. INDEX `fk_apps_has_accounts_accounts1_idx` (`uid` ASC),
  87. INDEX `fk_apps_has_accounts_apps1_idx` (`appid` ASC),
  88. CONSTRAINT `fk_apps_has_accounts_apps1`
  89. FOREIGN KEY (`appid`)
  90. REFERENCES `accounthub`.`apps` (`appid`)
  91. ON DELETE NO ACTION
  92. ON UPDATE NO ACTION,
  93. CONSTRAINT `fk_apps_has_accounts_accounts1`
  94. FOREIGN KEY (`uid`)
  95. REFERENCES `accounthub`.`accounts` (`uid`)
  96. ON DELETE NO ACTION
  97. ON UPDATE NO ACTION)
  98. ENGINE = InnoDB;
  99. -- -----------------------------------------------------
  100. -- Table `accounthub`.`apikeys`
  101. -- -----------------------------------------------------
  102. CREATE TABLE IF NOT EXISTS `accounthub`.`apikeys` (
  103. `key` VARCHAR(60) NOT NULL,
  104. `notes` TEXT NULL,
  105. PRIMARY KEY (`key`))
  106. ENGINE = InnoDB;
  107. -- -----------------------------------------------------
  108. -- Table `accounthub`.`groups`
  109. -- -----------------------------------------------------
  110. CREATE TABLE IF NOT EXISTS `accounthub`.`groups` (
  111. `groupid` INT NOT NULL AUTO_INCREMENT,
  112. `groupname` VARCHAR(45) NOT NULL,
  113. PRIMARY KEY (`groupid`),
  114. UNIQUE INDEX `groupid_UNIQUE` (`groupid` ASC),
  115. UNIQUE INDEX `groupname_UNIQUE` (`groupname` ASC))
  116. ENGINE = InnoDB;
  117. -- -----------------------------------------------------
  118. -- Table `accounthub`.`assigned_groups`
  119. -- -----------------------------------------------------
  120. CREATE TABLE IF NOT EXISTS `accounthub`.`assigned_groups` (
  121. `groupid` INT NOT NULL,
  122. `uid` INT NOT NULL,
  123. PRIMARY KEY (`groupid`, `uid`),
  124. INDEX `fk_groups_has_accounts_accounts1_idx` (`uid` ASC),
  125. INDEX `fk_groups_has_accounts_groups1_idx` (`groupid` ASC),
  126. CONSTRAINT `fk_groups_has_accounts_groups1`
  127. FOREIGN KEY (`groupid`)
  128. REFERENCES `accounthub`.`groups` (`groupid`)
  129. ON DELETE NO ACTION
  130. ON UPDATE NO ACTION,
  131. CONSTRAINT `fk_groups_has_accounts_accounts1`
  132. FOREIGN KEY (`uid`)
  133. REFERENCES `accounthub`.`accounts` (`uid`)
  134. ON DELETE NO ACTION
  135. ON UPDATE NO ACTION)
  136. ENGINE = InnoDB;
  137. -- -----------------------------------------------------
  138. -- Table `accounthub`.`managers`
  139. -- -----------------------------------------------------
  140. CREATE TABLE IF NOT EXISTS `accounthub`.`managers` (
  141. `managerid` INT NOT NULL,
  142. `employeeid` INT NOT NULL,
  143. PRIMARY KEY (`managerid`, `employeeid`),
  144. INDEX `fk_managers_accounts2_idx` (`employeeid` ASC),
  145. CONSTRAINT `fk_managers_accounts1`
  146. FOREIGN KEY (`managerid`)
  147. REFERENCES `accounthub`.`accounts` (`uid`)
  148. ON DELETE NO ACTION
  149. ON UPDATE NO ACTION,
  150. CONSTRAINT `fk_managers_accounts2`
  151. FOREIGN KEY (`employeeid`)
  152. REFERENCES `accounthub`.`accounts` (`uid`)
  153. ON DELETE NO ACTION
  154. ON UPDATE NO ACTION)
  155. ENGINE = InnoDB;
  156. -- -----------------------------------------------------
  157. -- Table `accounthub`.`logtypes`
  158. -- -----------------------------------------------------
  159. CREATE TABLE IF NOT EXISTS `accounthub`.`logtypes` (
  160. `logtype` INT NOT NULL,
  161. `typename` VARCHAR(45) NULL,
  162. PRIMARY KEY (`logtype`),
  163. UNIQUE INDEX `logtype_UNIQUE` (`logtype` ASC))
  164. ENGINE = InnoDB;
  165. -- -----------------------------------------------------
  166. -- Table `accounthub`.`authlog`
  167. -- -----------------------------------------------------
  168. CREATE TABLE IF NOT EXISTS `accounthub`.`authlog` (
  169. `logid` INT NOT NULL AUTO_INCREMENT,
  170. `logtime` DATETIME NOT NULL,
  171. `logtype` INT NOT NULL,
  172. `uid` INT NULL,
  173. `ip` VARCHAR(45) NULL,
  174. `otherdata` VARCHAR(255) NULL,
  175. PRIMARY KEY (`logid`),
  176. UNIQUE INDEX `logid_UNIQUE` (`logid` ASC),
  177. INDEX `fk_authlog_logtypes1_idx` (`logtype` ASC),
  178. INDEX `fk_authlog_accounts1_idx` (`uid` ASC),
  179. CONSTRAINT `fk_authlog_logtypes1`
  180. FOREIGN KEY (`logtype`)
  181. REFERENCES `accounthub`.`logtypes` (`logtype`)
  182. ON DELETE NO ACTION
  183. ON UPDATE NO ACTION,
  184. CONSTRAINT `fk_authlog_accounts1`
  185. FOREIGN KEY (`uid`)
  186. REFERENCES `accounthub`.`accounts` (`uid`)
  187. ON DELETE NO ACTION
  188. ON UPDATE NO ACTION)
  189. ENGINE = InnoDB;
  190. -- -----------------------------------------------------
  191. -- Table `accounthub`.`permissions`
  192. -- -----------------------------------------------------
  193. CREATE TABLE IF NOT EXISTS `accounthub`.`permissions` (
  194. `permid` INT NOT NULL AUTO_INCREMENT,
  195. `permcode` VARCHAR(45) NOT NULL,
  196. `perminfo` VARCHAR(200) NULL,
  197. PRIMARY KEY (`permid`),
  198. UNIQUE INDEX `permid_UNIQUE` (`permid` ASC))
  199. ENGINE = InnoDB;
  200. -- -----------------------------------------------------
  201. -- Table `accounthub`.`assigned_permissions`
  202. -- -----------------------------------------------------
  203. CREATE TABLE IF NOT EXISTS `accounthub`.`assigned_permissions` (
  204. `uid` INT NOT NULL,
  205. `permid` INT NOT NULL,
  206. PRIMARY KEY (`uid`, `permid`),
  207. INDEX `fk_permissions_has_accounts_accounts1_idx` (`uid` ASC),
  208. INDEX `fk_permissions_has_accounts_permissions1_idx` (`permid` ASC),
  209. CONSTRAINT `fk_permissions_has_accounts_permissions1`
  210. FOREIGN KEY (`permid`)
  211. REFERENCES `accounthub`.`permissions` (`permid`)
  212. ON DELETE NO ACTION
  213. ON UPDATE NO ACTION,
  214. CONSTRAINT `fk_permissions_has_accounts_accounts1`
  215. FOREIGN KEY (`uid`)
  216. REFERENCES `accounthub`.`accounts` (`uid`)
  217. ON DELETE NO ACTION
  218. ON UPDATE NO ACTION)
  219. ENGINE = InnoDB;
  220. -- -----------------------------------------------------
  221. -- Table `accounthub`.`mobile_codes`
  222. -- -----------------------------------------------------
  223. CREATE TABLE IF NOT EXISTS `accounthub`.`mobile_codes` (
  224. `codeid` INT NOT NULL AUTO_INCREMENT,
  225. `uid` INT NOT NULL,
  226. `code` VARCHAR(45) NOT NULL DEFAULT '',
  227. `description` VARCHAR(255) NOT NULL DEFAULT '',
  228. PRIMARY KEY (`codeid`),
  229. UNIQUE INDEX `codeid_UNIQUE` (`codeid` ASC),
  230. INDEX `fk_mobile_codes_accounts1_idx` (`uid` ASC),
  231. UNIQUE INDEX `code_UNIQUE` (`code` ASC),
  232. CONSTRAINT `fk_mobile_codes_accounts1`
  233. FOREIGN KEY (`uid`)
  234. REFERENCES `accounthub`.`accounts` (`uid`)
  235. ON DELETE NO ACTION
  236. ON UPDATE NO ACTION)
  237. ENGINE = InnoDB;
  238. -- -----------------------------------------------------
  239. -- Table `accounthub`.`rate_limit`
  240. -- -----------------------------------------------------
  241. CREATE TABLE IF NOT EXISTS `accounthub`.`rate_limit` (
  242. `ipaddr` VARCHAR(45) NOT NULL,
  243. `lastaction` DATETIME NULL,
  244. PRIMARY KEY (`ipaddr`))
  245. ENGINE = MEMORY;
  246. -- -----------------------------------------------------
  247. -- Table `accounthub`.`onetimekeys`
  248. -- -----------------------------------------------------
  249. CREATE TABLE IF NOT EXISTS `accounthub`.`onetimekeys` (
  250. `key` VARCHAR(10) NOT NULL,
  251. `uid` INT NOT NULL,
  252. `expires` DATETIME NOT NULL,
  253. INDEX `fk_onetimekeys_accounts1_idx` (`uid` ASC),
  254. PRIMARY KEY (`key`),
  255. UNIQUE INDEX `key_UNIQUE` (`key` ASC),
  256. CONSTRAINT `fk_onetimekeys_accounts1`
  257. FOREIGN KEY (`uid`)
  258. REFERENCES `accounthub`.`accounts` (`uid`)
  259. ON DELETE NO ACTION
  260. ON UPDATE NO ACTION)
  261. ENGINE = InnoDB;
  262. SET SQL_MODE=@OLD_SQL_MODE;
  263. SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  264. SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  265. -- -----------------------------------------------------
  266. -- Data for table `accounthub`.`acctstatus`
  267. -- -----------------------------------------------------
  268. START TRANSACTION;
  269. USE `accounthub`;
  270. INSERT INTO `accounthub`.`acctstatus` (`statusid`, `statuscode`) VALUES (1, 'NORMAL');
  271. INSERT INTO `accounthub`.`acctstatus` (`statusid`, `statuscode`) VALUES (2, 'LOCKED_OR_DISABLED');
  272. INSERT INTO `accounthub`.`acctstatus` (`statusid`, `statuscode`) VALUES (3, 'CHANGE_PASSWORD');
  273. INSERT INTO `accounthub`.`acctstatus` (`statusid`, `statuscode`) VALUES (4, 'TERMINATED');
  274. INSERT INTO `accounthub`.`acctstatus` (`statusid`, `statuscode`) VALUES (5, 'ALERT_ON_ACCESS');
  275. COMMIT;
  276. -- -----------------------------------------------------
  277. -- Data for table `accounthub`.`accttypes`
  278. -- -----------------------------------------------------
  279. START TRANSACTION;
  280. USE `accounthub`;
  281. INSERT INTO `accounthub`.`accttypes` (`typeid`, `typecode`) VALUES (1, 'LOCAL');
  282. INSERT INTO `accounthub`.`accttypes` (`typeid`, `typecode`) VALUES (2, 'LDAP');
  283. INSERT INTO `accounthub`.`accttypes` (`typeid`, `typecode`) VALUES (3, 'LIGHT');
  284. COMMIT;
  285. -- -----------------------------------------------------
  286. -- Data for table `accounthub`.`logtypes`
  287. -- -----------------------------------------------------
  288. START TRANSACTION;
  289. USE `accounthub`;
  290. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (1, 'PORTAL_LOGIN_OK');
  291. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (2, 'PORTAL_LOGIN_FAILED');
  292. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (3, 'PASSWORD_CHANGED');
  293. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (4, 'API_LOGIN_OK');
  294. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (5, 'API_LOGIN_FAILED');
  295. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (6, 'PORTAL_BAD_AUTHCODE');
  296. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (7, 'API_BAD_AUTHCODE');
  297. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (8, 'BAD_CAPTCHA');
  298. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (9, '2FA_ADDED');
  299. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (10, '2FA_REMOVED');
  300. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (11, 'PORTAL_LOGOUT');
  301. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (12, 'API_AUTH_OK');
  302. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (13, 'API_AUTH_FAILED');
  303. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (14, 'API_BAD_KEY');
  304. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (15, 'LOG_CLEARED');
  305. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (16, 'USER_REMOVED');
  306. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (17, 'USER_ADDED');
  307. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (18, 'USER_EDITED');
  308. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (19, 'MOBILE_LOGIN_OK');
  309. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (20, 'MOBILE_LOGIN_FAILED');
  310. INSERT INTO `accounthub`.`logtypes` (`logtype`, `typename`) VALUES (21, 'MOBILE_BAD_KEY');
  311. COMMIT;
  312. -- -----------------------------------------------------
  313. -- Data for table `accounthub`.`permissions`
  314. -- -----------------------------------------------------
  315. START TRANSACTION;
  316. USE `accounthub`;
  317. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (1, 'ADMIN', 'System administrator');
  318. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (100, 'INV_VIEW', 'Access inventory system');
  319. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (101, 'INV_EDIT', 'Edit inventory system');
  320. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (200, 'TASKFLOOR', 'Access TaskFloor');
  321. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (300, 'QWIKCLOCK', 'Access QwikClock and punch in/out');
  322. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (301, 'QWIKCLOCK_MANAGE', 'Edit punches and other data for managed users');
  323. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (302, 'QWIKCLOCK_EDITSELF', 'Edit own punches and other data');
  324. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (303, 'QWIKCLOCK_ADMIN', 'Add and edit shifts and other data for all users');
  325. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (400, 'SITEWRITER', 'Manage and edit websites, messages, and analytics');
  326. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (401, 'SITEWRITER_CONTACT', 'Manage messages sent via website contact forms');
  327. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (402, 'SITEWRITER_ANALYTICS', 'View website analytics');
  328. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (403, 'SITEWRITER_EDIT', 'Edit website content');
  329. INSERT INTO `accounthub`.`permissions` (`permid`, `permcode`, `perminfo`) VALUES (404, 'SITEWRITER_FILES', 'Manage and upload files');
  330. COMMIT;