-- ----------------------------
-- Table structure for sys_user
-- ----------------------------
ALTER TABLE "sys_user" RENAME TO "sys_user_old";
CREATE TABLE "sys_user" (
  "user_id" integer NOT NULL,
  "dept_id" integer,
  "user_name" text(36) NOT NULL,
  "nick_name" text(36) NOT NULL,
  "email" text(64),
  "phone" text(32),
  "sex" text(1),
  "avatar" text(255),
  "password" text(128),
  "user_type" text(20),
  "user_source" text(32),
  "status_flag" text(1),
  "del_flag" text(1),
  "password_update_time" integer,
  "login_count" integer,
  "login_ip" text(128),
  "login_time" integer,
  "create_by" text(64),
  "create_time" integer,
  "update_by" text(64),
  "update_time" integer,
  "remark" text(200),
  PRIMARY KEY ("user_id")
);

-- ----------------------------
-- Records of sys_user
-- ----------------------------
INSERT INTO "sys_user" (
"user_id", "dept_id", "user_name", "nick_name", "email", "phone", "sex", "avatar", "password", "status_flag", "del_flag", "password_update_time", "login_count", "login_ip", "login_time", "create_by", "create_time", "update_by", "update_time", "remark") 
SELECT 
"user_id", "dept_id", "user_name", "nick_name", "email", "phone", "sex", "avatar", "password", "status_flag", "del_flag", "password_update_time", "login_count", "login_ip", "login_time", "create_by", "create_time", "update_by", "update_time", "remark" 
FROM "sys_user_old";

-- UPDATE "user_type", "user_source" 
UPDATE sys_user SET 
user_type = COALESCE((SELECT user_type FROM sys_user_old WHERE sys_user_old.user_id = sys_user.user_id), 'Sytem'),
user_source = COALESCE((SELECT user_source FROM sys_user_old WHERE sys_user_old.user_id = sys_user.user_id), '#')
WHERE EXISTS (SELECT 1 FROM sys_user_old WHERE sys_user_old.user_id = sys_user.user_id);

DROP TABLE IF EXISTS "sys_user_old";