DROP SEQUENCE if EXISTS "public"."user_id_seq";
CREATE SEQUENCE "public"."user_id_seq"
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
DROP TABLE IF EXISTS "public"."user";
CREATE TABLE "public"."user" (
  "id" int4 NOT NULL DEFAULT nextval('user_id_seq'::regclass),
  "name" varchar(64) COLLATE "pg_catalog"."default" NOT NULL,
  "username" varchar(64) COLLATE "pg_catalog"."default" NOT NULL,
  "password" varchar(512) COLLATE "pg_catalog"."default" NOT NULL,
  "department_id" int4 NOT NULL,
  "email" varchar(128) COLLATE "pg_catalog"."default",
  "enable" bool NOT NULL DEFAULT true,
  "delete" bool NOT NULL DEFAULT false,
  "phone" varchar(20) COLLATE "pg_catalog"."default" NOT NULL,
  "post" varchar(64) COLLATE "pg_catalog"."default"
);
COMMENT ON COLUMN "public"."user"."username" IS '用户名 账号';
COMMENT ON COLUMN "public"."user"."department_id" IS '部门id';
COMMENT ON COLUMN "public"."user"."enable" IS '启用状态';
COMMENT ON COLUMN "public"."user"."phone" IS '手机号(小程序使用手机号登录)';
COMMENT ON COLUMN "public"."user"."post" IS '职位';


DROP TABLE IF EXISTS "public"."resource";
CREATE TABLE "public"."resource" (
  "code" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "name" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "parent_resource" varchar(128) COLLATE "pg_catalog"."default"
);
COMMENT ON TABLE "public"."resource" IS '权限字典';


DROP SEQUENCE if EXISTS "public"."user_resource_id_seq";
CREATE SEQUENCE "public"."user_resource_id_seq"
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
DROP TABLE IF EXISTS "public"."user_resource";
CREATE TABLE "public"."user_resource" (
  "id" int4 NOT NULL DEFAULT nextval('user_resource_id_seq'::regclass),
  "user_id" int4 NOT NULL,
  "resource" varchar(128) COLLATE "pg_catalog"."default" NOT NULL
);


DROP TABLE IF EXISTS "public"."user_token";
CREATE TABLE "public"."user_token" (
  "token" uuid NOT NULL,
  "user_info" jsonb NOT NULL,
  "expired" timestamptz(6) NOT NULL
);


DROP SEQUENCE if EXISTS "public"."department_id_seq";
CREATE SEQUENCE "public"."department_id_seq" 
INCREMENT 1
MINVALUE  1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
DROP TABLE IF EXISTS "public"."department";
CREATE TABLE "public"."department" (
  "id" int4 NOT NULL DEFAULT nextval('department_id_seq'::regclass),
  "name" varchar(128) COLLATE "pg_catalog"."default" NOT NULL,
  "dependence" int4,
  "type" int4
);
COMMENT ON COLUMN "public"."department"."dependence" IS '上级部门/从属';
-- COMMENT ON COLUMN "public"."department"."type" IS '市1，区县2，乡镇3，村4';
