/*
 Navicat Premium Data Transfer

 Source Server         : 智慧法务
 Source Server Type    : PostgreSQL
 Source Server Version : 170005
 Source Host           : nas.7bm.co:54302
 Source Catalog        : docauditai
 Source Schema         : public

 Target Server Type    : PostgreSQL
 Target Server Version : 170005
 File Encoding         : 65001

 Date: 18/07/2025 20:16:41
*/


-- ----------------------------
-- Table structure for roles
-- ----------------------------
DROP TABLE IF EXISTS "public"."roles";
CREATE TABLE "public"."roles" (
  "id" int4 NOT NULL DEFAULT nextval('user_role_id_seq'::regclass),
  "role_key" varchar(30) COLLATE "pg_catalog"."default" NOT NULL,
  "role_name" varchar(50) COLLATE "pg_catalog"."default" NOT NULL,
  "data_scope" varchar(20) COLLATE "pg_catalog"."default" DEFAULT 'SELF'::character varying,
  "description" varchar(200) COLLATE "pg_catalog"."default" DEFAULT ''::character varying,
  "created_at" timestamptz(6) DEFAULT now(),
  "updated_at" timestamptz(6) DEFAULT now()
)
;
COMMENT ON COLUMN "public"."roles"."id" IS '角色ID';
COMMENT ON COLUMN "public"."roles"."role_key" IS '角色标识(如：admin, common, deptLeader, groupLeader)';
COMMENT ON COLUMN "public"."roles"."role_name" IS '角色名称(如：系统管理员, 普通员工)';
COMMENT ON COLUMN "public"."roles"."data_scope" IS '数据权限范围(SELF=仅自己, GROUP=本组, DEPT=本部门, ALL=全部)';
COMMENT ON COLUMN "public"."roles"."description" IS '角色描述';
COMMENT ON COLUMN "public"."roles"."created_at" IS '创建时间';
COMMENT ON COLUMN "public"."roles"."updated_at" IS '更新时间';
COMMENT ON TABLE "public"."roles" IS '系统角色表';

-- ----------------------------
-- Records of roles
-- ----------------------------
INSERT INTO "public"."roles" VALUES (1, 'admin', '系统管理员', 'ALL', '拥有系统全部操作权限', '2025-07-18 02:35:39.367459+00', '2025-07-18 02:35:39.367459+00');
INSERT INTO "public"."roles" VALUES (2, 'common', '普通员工', 'SELF', '仅能操作自己的数据', '2025-07-18 02:35:39.367459+00', '2025-07-18 02:35:39.367459+00');
INSERT INTO "public"."roles" VALUES (3, 'deptLeader', '部门主管', 'DEPT', '可操作本部门的数据', '2025-07-18 02:35:39.367459+00', '2025-07-18 02:35:39.367459+00');
INSERT INTO "public"."roles" VALUES (4, 'groupLeader', '小组组长', 'GROUP', '可操作本小组的数据', '2025-07-18 02:35:39.367459+00', '2025-07-18 02:35:39.367459+00');

-- ----------------------------
-- Triggers structure for table roles
-- ----------------------------
CREATE TRIGGER "update_user_role_updated_at" BEFORE UPDATE ON "public"."roles"
FOR EACH ROW
EXECUTE PROCEDURE "public"."update_updated_at"();

-- ----------------------------
-- Uniques structure for table roles
-- ----------------------------
ALTER TABLE "public"."roles" ADD CONSTRAINT "roles_role_key_key" UNIQUE ("role_key");

-- ----------------------------
-- Primary Key structure for table roles
-- ----------------------------
ALTER TABLE "public"."roles" ADD CONSTRAINT "user_role_pkey" PRIMARY KEY ("id");
