update_20130318_1_to_20170328_1.sql 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*==============================================================*/
  2. /* DBMS name: MySQL 5.0 */
  3. /* Created on: 2017/3/28 21:32:32 */
  4. /*==============================================================*/
  5. drop table if exists tmp_upms_organization;
  6. rename table upms_organization to tmp_upms_organization;
  7. drop table if exists tmp_upms_user_permission;
  8. rename table upms_user_permission to tmp_upms_user_permission;
  9. alter table upms_log
  10. modify column parameter mediumtext;
  11. alter table upms_log
  12. modify column result mediumtext;
  13. /*==============================================================*/
  14. /* Table: upms_organization */
  15. /*==============================================================*/
  16. create table upms_organization
  17. (
  18. organization_id int(10) unsigned not null auto_increment comment '编号',
  19. pid int(10) comment '所属上级',
  20. name varchar(20) comment '组织名称',
  21. description varchar(1000) comment '组织描述',
  22. ctime bigint(20) comment '创建时间',
  23. primary key (organization_id)
  24. );
  25. alter table upms_organization comment '组织';
  26. insert into upms_organization (organization_id, name, description, ctime)
  27. select organization_id, name, description, ctime
  28. from tmp_upms_organization;
  29. /*==============================================================*/
  30. /* Table: upms_user_permission */
  31. /*==============================================================*/
  32. create table upms_user_permission
  33. (
  34. user_permission_id int(10) unsigned not null auto_increment comment '编号',
  35. user_id int(10) unsigned not null comment '用户编号',
  36. permission_id int(10) unsigned not null comment '权限编号',
  37. type tinyint(4) not null comment '权限类型(-1:减权限,1:增权限)',
  38. primary key (user_permission_id)
  39. );
  40. alter table upms_user_permission comment '用户权限关联表';
  41. #WARNING: The following insert order will fail because it cannot give value to mandatory columns
  42. insert into upms_user_permission (user_permission_id, user_id, permission_id, type)
  43. select user_permission_id, user_id, permission_id, ?
  44. from tmp_upms_user_permission;
  45. alter table upms_user_organization add constraint FK_Reference_19 foreign key (organization_id)
  46. references upms_organization (organization_id) on delete restrict on update restrict;
  47. alter table upms_user_permission add constraint FK_Reference_24 foreign key (user_id)
  48. references upms_user (user_id) on delete restrict on update restrict;
  49. alter table upms_user_permission add constraint FK_Reference_25 foreign key (permission_id)
  50. references upms_permission (permission_id) on delete restrict on update restrict;