You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

n9e_rdb.sql 13 kB

5 years ago
Rdb (#479) * use collector interface * mysql can work fine * add basecollector * add prober & monapi.plugins * enable mysql plugins work * rename collector -> manager * add white list access check for rdb * add cache module for authConfig & session * rollback n9e_rdb_3.3.0.sql * add sql ddl document * add white_list, pwd, login access control * add email code for login & reset password * use sessionUsername instead of cookieUsername * remove cookie name and data from session * rename userName to username * add remote_addr with session connection * add get user by sid with cache * enable cookie life time could be zero * go mod tidy * Rdb with session & monapi with telegraf (#456) * use collector interface * mysql can work fine * add basecollector * add prober & monapi.plugins * enable mysql plugins work * rename collector -> manager * add white list access check for rdb * add cache module for authConfig & session * rollback n9e_rdb_3.3.0.sql * add sql ddl document * add white_list, pwd, login access control * add email code for login & reset password * use sessionUsername instead of cookieUsername * remove cookie name and data from session * rename userName to username * add remote_addr with session connection * add get user by sid with cache * enable cookie life time could be zero * go mod tidy * add plugins config for prober * add prober plugin expression parse * update transfer default config for m3 * Rdb (#458) * bugfix: session gc * use flag for pwdMustInclude * change user login function * delete invite token after use * bugfix: login response * add sessionStart middle ware * add auth module * add i18n for rdb * add i18n.zh for rdb.auth * add mon plugins(redis, mongodb) * update config * add sub struct into definitions * clean up sid cache after session destory * bugfix: get user return nil when not found * update i18n * bugfix: ignore cache nologin user * add user for callback output * add password change api * update default configfile & sql patch * merge mon http middleware from rdb * remove sso logout, sso already supporte one time auth
5 years ago
5 years ago
5 years ago
5 years ago
Rdb (#479) * use collector interface * mysql can work fine * add basecollector * add prober & monapi.plugins * enable mysql plugins work * rename collector -> manager * add white list access check for rdb * add cache module for authConfig & session * rollback n9e_rdb_3.3.0.sql * add sql ddl document * add white_list, pwd, login access control * add email code for login & reset password * use sessionUsername instead of cookieUsername * remove cookie name and data from session * rename userName to username * add remote_addr with session connection * add get user by sid with cache * enable cookie life time could be zero * go mod tidy * Rdb with session & monapi with telegraf (#456) * use collector interface * mysql can work fine * add basecollector * add prober & monapi.plugins * enable mysql plugins work * rename collector -> manager * add white list access check for rdb * add cache module for authConfig & session * rollback n9e_rdb_3.3.0.sql * add sql ddl document * add white_list, pwd, login access control * add email code for login & reset password * use sessionUsername instead of cookieUsername * remove cookie name and data from session * rename userName to username * add remote_addr with session connection * add get user by sid with cache * enable cookie life time could be zero * go mod tidy * add plugins config for prober * add prober plugin expression parse * update transfer default config for m3 * Rdb (#458) * bugfix: session gc * use flag for pwdMustInclude * change user login function * delete invite token after use * bugfix: login response * add sessionStart middle ware * add auth module * add i18n for rdb * add i18n.zh for rdb.auth * add mon plugins(redis, mongodb) * update config * add sub struct into definitions * clean up sid cache after session destory * bugfix: get user return nil when not found * update i18n * bugfix: ignore cache nologin user * add user for callback output * add password change api * update default configfile & sql patch * merge mon http middleware from rdb * remove sso logout, sso already supporte one time auth
5 years ago
5 years ago
Rdb (#479) * use collector interface * mysql can work fine * add basecollector * add prober & monapi.plugins * enable mysql plugins work * rename collector -> manager * add white list access check for rdb * add cache module for authConfig & session * rollback n9e_rdb_3.3.0.sql * add sql ddl document * add white_list, pwd, login access control * add email code for login & reset password * use sessionUsername instead of cookieUsername * remove cookie name and data from session * rename userName to username * add remote_addr with session connection * add get user by sid with cache * enable cookie life time could be zero * go mod tidy * Rdb with session & monapi with telegraf (#456) * use collector interface * mysql can work fine * add basecollector * add prober & monapi.plugins * enable mysql plugins work * rename collector -> manager * add white list access check for rdb * add cache module for authConfig & session * rollback n9e_rdb_3.3.0.sql * add sql ddl document * add white_list, pwd, login access control * add email code for login & reset password * use sessionUsername instead of cookieUsername * remove cookie name and data from session * rename userName to username * add remote_addr with session connection * add get user by sid with cache * enable cookie life time could be zero * go mod tidy * add plugins config for prober * add prober plugin expression parse * update transfer default config for m3 * Rdb (#458) * bugfix: session gc * use flag for pwdMustInclude * change user login function * delete invite token after use * bugfix: login response * add sessionStart middle ware * add auth module * add i18n for rdb * add i18n.zh for rdb.auth * add mon plugins(redis, mongodb) * update config * add sub struct into definitions * clean up sid cache after session destory * bugfix: get user return nil when not found * update i18n * bugfix: ignore cache nologin user * add user for callback output * add password change api * update default configfile & sql patch * merge mon http middleware from rdb * remove sso logout, sso already supporte one time auth
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. set names utf8;
  2. drop database if exists n9e_rdb;
  3. create database n9e_rdb;
  4. use n9e_rdb;
  5. CREATE TABLE `user`
  6. (
  7. `id` int unsigned not null AUTO_INCREMENT,
  8. `uuid` varchar(128) not null comment 'use in cookie',
  9. `username` varchar(64) not null comment 'login name, cannot rename',
  10. `password` varchar(128) not null default '',
  11. `passwords` varchar(512) not null default '',
  12. `dispname` varchar(32) not null default '' comment 'display name, chinese name',
  13. `phone` varchar(16) not null default '',
  14. `email` varchar(64) not null default '',
  15. `im` varchar(64) not null default '',
  16. `portrait` varchar(2048) not null default '',
  17. `intro` varchar(2048) not null default '',
  18. `organization` varchar(255) not null default '',
  19. `typ` tinyint(1) not null default 0 comment '0: long-term account; 1: temporary account',
  20. `status` tinyint(1) not null default 0 comment '0: active, 1: inactive, 2: locked, 3: frozen, 5: writen-off',
  21. `is_root` tinyint(1) not null,
  22. `leader_id` int unsigned not null default 0,
  23. `leader_name` varchar(32) not null default '',
  24. `login_err_num` int unsigned not null default 0,
  25. `active_begin` bigint not null default 0,
  26. `active_end` bigint not null default 0,
  27. `locked_at` bigint not null default 0,
  28. `updated_at` bigint not null default 0,
  29. `pwd_updated_at` bigint not null default 0,
  30. `logged_at` bigint not null default 0,
  31. `create_at` timestamp not null default CURRENT_TIMESTAMP,
  32. PRIMARY KEY (`id`),
  33. UNIQUE KEY (`username`),
  34. UNIQUE KEY (`uuid`)
  35. ) ENGINE = InnoDB
  36. DEFAULT CHARSET = utf8;
  37. CREATE TABLE `user_token`
  38. (
  39. `user_id` int unsigned not null,
  40. `username` varchar(128) not null,
  41. `token` varchar(128) not null,
  42. KEY (`user_id`),
  43. KEY (`username`),
  44. UNIQUE KEY (`token`)
  45. ) ENGINE = InnoDB
  46. DEFAULT CHARSET = utf8;
  47. CREATE TABLE `invite`
  48. (
  49. `id` int unsigned not null AUTO_INCREMENT,
  50. `token` varchar(128) not null,
  51. `expire` bigint not null,
  52. `creator` varchar(32) not null,
  53. PRIMARY KEY (`id`),
  54. UNIQUE KEY (`token`)
  55. ) ENGINE = InnoDB
  56. DEFAULT CHARSET = utf8;
  57. CREATE TABLE `team`
  58. (
  59. `id` int unsigned not null AUTO_INCREMENT,
  60. `ident` varchar(255) not null,
  61. `name` varchar(255) not null default '',
  62. `note` varchar(255) not null default '',
  63. `mgmt` int(1) not null comment '0: member manage; 1: admin manage',
  64. `creator` int unsigned not null,
  65. `last_updated` timestamp not null default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  66. PRIMARY KEY (`id`),
  67. UNIQUE KEY (`ident`)
  68. ) ENGINE = InnoDB
  69. DEFAULT CHARSET = utf8;
  70. CREATE TABLE `team_user`
  71. (
  72. `team_id` int unsigned not null,
  73. `user_id` int unsigned not null,
  74. `is_admin` tinyint(1) not null,
  75. KEY (`team_id`),
  76. KEY (`user_id`)
  77. ) ENGINE = InnoDB
  78. DEFAULT CHARSET = utf8;
  79. CREATE TABLE `configs`
  80. (
  81. `id` int unsigned not null AUTO_INCREMENT,
  82. `ckey` varchar(255) not null,
  83. `cval` varchar(255) not null default '',
  84. `last_updated` timestamp not null default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  85. PRIMARY KEY (`id`),
  86. UNIQUE KEY (`ckey`)
  87. ) ENGINE = InnoDB
  88. DEFAULT CHARSET = utf8;
  89. CREATE TABLE `node_cate`
  90. (
  91. `id` int unsigned not null AUTO_INCREMENT,
  92. `ident` char(128) not null default '' comment 'cluster,service,module,department,product...',
  93. `name` varchar(255) not null default '',
  94. `icon_color` char(7) not null default '' comment 'e.g. #108AC6',
  95. `protected` tinyint(1) not null default 0 comment 'if =1, cannot delete',
  96. PRIMARY KEY (`id`),
  97. KEY (`ident`)
  98. ) ENGINE = InnoDB
  99. DEFAULT CHARSET = utf8;
  100. insert into node_cate(ident, name, icon_color, protected)
  101. values ('tenant', '租户', '#de83cb', 1);
  102. insert into node_cate(ident, name, icon_color, protected)
  103. values ('organization', '组织', '#ff8e75', 1);
  104. insert into node_cate(ident, name, icon_color, protected)
  105. values ('project', '项目', '#f6bb4a', 1);
  106. insert into node_cate(ident, name, icon_color, protected)
  107. values ('module', '模块', '#6dc448', 1);
  108. insert into node_cate(ident, name, icon_color, protected)
  109. values ('cluster', '集群', '#94c7c6', 1);
  110. insert into node_cate(ident, name, icon_color, protected)
  111. values ('resource', '资源', '#a7aae6', 1);
  112. CREATE TABLE `node_cate_field`
  113. (
  114. `id` int unsigned not null AUTO_INCREMENT,
  115. `cate` char(32) not null default '' comment 'cluster,service,module,department,product...',
  116. `field_ident` varchar(255) not null comment 'english identity',
  117. `field_name` varchar(255) not null comment 'chinese name',
  118. `field_type` varchar(64) not null,
  119. `field_required` tinyint(1) not null default 0,
  120. `field_extra` varchar(2048) not null default '',
  121. `last_updated` timestamp not null default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  122. PRIMARY KEY (`id`),
  123. KEY (`cate`)
  124. ) ENGINE = InnoDB
  125. DEFAULT CHARSET = utf8;
  126. CREATE TABLE `node_field_value`
  127. (
  128. `id` int unsigned not null AUTO_INCREMENT,
  129. `node_id` int unsigned not null,
  130. `field_ident` varchar(255) not null,
  131. `field_value` varchar(1024) not null default '',
  132. PRIMARY KEY (`id`),
  133. KEY (`node_id`)
  134. ) ENGINE = InnoDB
  135. DEFAULT CHARSET = utf8;
  136. CREATE TABLE `node`
  137. (
  138. `id` int unsigned not null AUTO_INCREMENT,
  139. `pid` int unsigned not null,
  140. `ident` varchar(128) not null,
  141. `name` varchar(255) not null default '',
  142. `note` varchar(255) not null default '',
  143. `path` varchar(255) not null comment 'ident1.ident2.ident3',
  144. `leaf` tinyint(1) not null,
  145. `cate` char(128) not null default '' comment 'cluster,service,module,department,product...',
  146. `icon_color` char(7) not null default '' comment 'e.g. #108AC6',
  147. `icon_char` char(1) not null default '' comment 'cluster->C,service->S,module->M',
  148. `proxy` tinyint(1) not null default 0 comment '0:myself management, 1:other module management',
  149. `creator` varchar(64) not null,
  150. `last_updated` timestamp not null default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  151. PRIMARY KEY (`id`),
  152. UNIQUE KEY (`path`),
  153. KEY (`cate`)
  154. ) ENGINE = InnoDB
  155. DEFAULT CHARSET = utf8;
  156. insert into node(id, ident, name, note, pid, path, leaf, cate, icon_color, icon_char, proxy, creator)
  157. values (1, 'inner', '内置租户', '用于平台管理视角的资源监控', 0, 'inner', 0, 'tenant', '#de83cb', 'T', 0, 'root');
  158. CREATE TABLE `node_trash`
  159. (
  160. `id` int unsigned not null,
  161. `pid` int unsigned not null,
  162. `ident` varchar(128) not null,
  163. `name` varchar(255) not null default '',
  164. `note` varchar(255) not null default '',
  165. `path` varchar(255) not null comment 'ident1.ident2.ident3',
  166. `leaf` tinyint(1) not null,
  167. `cate` char(128) not null default '' comment 'cluster,service,module,department,product...',
  168. `icon_color` char(7) not null default '' comment 'e.g. #108AC6',
  169. `icon_char` char(1) not null default '' comment 'cluster->C,service->S,module->M',
  170. `proxy` tinyint(1) not null default 0 comment '0:myself management, 1:other module management',
  171. `creator` varchar(64) not null,
  172. `last_updated` timestamp not null default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  173. PRIMARY KEY (`id`),
  174. KEY (`path`),
  175. KEY (`cate`)
  176. ) ENGINE = InnoDB
  177. DEFAULT CHARSET = utf8;
  178. CREATE TABLE `node_admin`
  179. (
  180. `node_id` int unsigned not null,
  181. `user_id` int unsigned not null,
  182. KEY (`node_id`),
  183. KEY (`user_id`)
  184. ) ENGINE = InnoDB
  185. DEFAULT CHARSET = utf8;
  186. CREATE TABLE `resource`
  187. (
  188. `id` int unsigned not null AUTO_INCREMENT,
  189. `uuid` varchar(255) not null,
  190. `ident` varchar(255) not null,
  191. `name` varchar(255) not null default '',
  192. `labels` varchar(255) not null default '' comment 'e.g. flavor=2c4g300g,region=bj,os=windows',
  193. `note` varchar(255) not null default '',
  194. `extend` varchar(1024) not null default '' comment 'json',
  195. `cate` varchar(64) not null comment 'host,vm,container,switch,redis,mongo',
  196. `tenant` varchar(128) not null default '',
  197. `last_updated` timestamp not null default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  198. PRIMARY KEY (`id`),
  199. UNIQUE KEY (`uuid`),
  200. UNIQUE KEY (`ident`),
  201. KEY (`tenant`)
  202. ) ENGINE = InnoDB
  203. DEFAULT CHARSET = utf8;
  204. CREATE TABLE `node_resource`
  205. (
  206. `node_id` int unsigned not null,
  207. `res_id` int unsigned not null,
  208. KEY (`node_id`),
  209. KEY (`res_id`)
  210. ) ENGINE = InnoDB
  211. DEFAULT CHARSET = utf8;
  212. CREATE TABLE `node_role`
  213. (
  214. `id` int unsigned not null AUTO_INCREMENT,
  215. `node_id` int unsigned not null,
  216. `username` varchar(64) not null,
  217. `role_id` int unsigned not null,
  218. PRIMARY KEY (`id`),
  219. KEY (`node_id`),
  220. KEY (`role_id`),
  221. KEY (`username`)
  222. ) ENGINE = InnoDB
  223. DEFAULT CHARSET = utf8;
  224. CREATE TABLE `role`
  225. (
  226. `id` int unsigned not null AUTO_INCREMENT,
  227. `name` varchar(128) not null default '',
  228. `note` varchar(255) not null default '',
  229. `cate` char(6) not null default '' comment 'category: global or local',
  230. PRIMARY KEY (`id`),
  231. UNIQUE KEY (`name`)
  232. ) ENGINE = InnoDB
  233. DEFAULT CHARSET = utf8;
  234. CREATE TABLE `role_operation`
  235. (
  236. `id` int unsigned not null AUTO_INCREMENT,
  237. `role_id` int unsigned not null,
  238. `operation` varchar(255) not null,
  239. PRIMARY KEY (`id`),
  240. KEY (`role_id`)
  241. ) ENGINE = InnoDB
  242. DEFAULT CHARSET = utf8;
  243. CREATE TABLE `role_global_user`
  244. (
  245. `role_id` int unsigned not null,
  246. `user_id` int unsigned not null,
  247. KEY (`role_id`),
  248. KEY (`user_id`)
  249. ) ENGINE = InnoDB
  250. DEFAULT CHARSET = utf8;
  251. CREATE TABLE `login_log`
  252. (
  253. `id` int unsigned not null AUTO_INCREMENT,
  254. `username` varchar(64) not null,
  255. `client` varchar(128) not null comment 'client ip',
  256. `clock` bigint not null comment 'login timestamp',
  257. `loginout` char(3) not null comment 'in or out',
  258. `err` varchar(128) not null comment 'err msg',
  259. PRIMARY KEY (`id`),
  260. KEY (`username`),
  261. KEY (`clock`)
  262. ) ENGINE = InnoDB
  263. DEFAULT CHARSET = utf8;
  264. CREATE TABLE `operation_log`
  265. (
  266. `id` bigint unsigned not null AUTO_INCREMENT,
  267. `username` varchar(64) not null,
  268. `clock` bigint not null comment 'operation timestamp',
  269. `res_cl` char(16) not null default '' comment 'resource class',
  270. `res_id` varchar(128) not null default '',
  271. `detail` varchar(512) not null,
  272. PRIMARY KEY (`id`),
  273. KEY (`clock`),
  274. KEY (`res_cl`, `res_id`)
  275. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  276. CREATE TABLE `login_code`
  277. (
  278. `username` varchar(64) not null comment 'login name, cannot rename',
  279. `code` varchar(32) not null,
  280. `login_type` varchar(32) not null,
  281. `created_at` bigint not null comment 'created at',
  282. KEY (`code`),
  283. KEY (`created_at`),
  284. UNIQUE KEY (`username`)
  285. ) ENGINE = InnoDB
  286. DEFAULT CHARSET = utf8;
  287. CREATE TABLE `auth_state` (
  288. `state` varchar(128) DEFAULT '' NOT NULL,
  289. `typ` varchar(32) DEFAULT '' NOT NULL COMMENT 'response_type',
  290. `redirect` varchar(1024) DEFAULT '' NOT NULL,
  291. `expires_at` bigint DEFAULT '0' NOT NULL,
  292. PRIMARY KEY (`state`)
  293. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  294. CREATE TABLE `captcha` (
  295. `captcha_id` varchar(128) NOT NULL,
  296. `answer` varchar(128) DEFAULT '' NOT NULL,
  297. `created_at` bigint DEFAULT '0' NOT NULL,
  298. KEY (`captcha_id`, `answer`),
  299. KEY (`created_at`)
  300. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  301. CREATE TABLE `white_list` (
  302. `id` bigint unsigned not null AUTO_INCREMENT,
  303. `start_ip` varchar(32) DEFAULT '0' NOT NULL,
  304. `end_ip` varchar(32) DEFAULT '0' NOT NULL,
  305. `start_ip_int` bigint DEFAULT '0' NOT NULL,
  306. `end_ip_int` bigint DEFAULT '0' NOT NULL,
  307. `start_time` bigint DEFAULT '0' NOT NULL,
  308. `end_time` bigint DEFAULT '0' NOT NULL,
  309. `created_at` bigint DEFAULT '0' NOT NULL,
  310. `updated_at` bigint DEFAULT '0' NOT NULL,
  311. `creator` varchar(64) DEFAULT '' NOT NULL,
  312. `updater` varchar(64) DEFAULT '' NOT NULL,
  313. PRIMARY KEY (`id`),
  314. KEY (`start_ip_int`, `end_ip_int`),
  315. KEY (`start_time`, `end_time`),
  316. KEY (`created_at`)
  317. ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
  318. CREATE TABLE `session` (
  319. `sid` char(128) NOT NULL,
  320. `username` varchar(64) DEFAULT '',
  321. `remote_addr` varchar(32) DEFAULT '',
  322. `created_at` integer unsigned DEFAULT '0',
  323. `updated_at` integer unsigned DEFAULT '0' NOT NULL,
  324. PRIMARY KEY (`sid`),
  325. KEY (`username`),
  326. KEY (`updated_at`)
  327. ) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8;