/*
 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: 17/07/2025 21:07:07
*/


-- ----------------------------
-- Table structure for sso_users
-- ----------------------------
DROP TABLE IF EXISTS "public"."sso_users";
CREATE TABLE "public"."sso_users" (
  "id" uuid NOT NULL DEFAULT gen_random_uuid(),
  "sub" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "username" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "nick_name" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "phone_number" varchar(20) COLLATE "pg_catalog"."default",
  "email" varchar(255) COLLATE "pg_catalog"."default",
  "ou_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "ou_name" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "status" int2 DEFAULT 0,
  "is_leader" bool DEFAULT false,
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "updated_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP,
  "deleted_at" timestamp(6)
)
;
COMMENT ON COLUMN "public"."sso_users"."id" IS '主键，数据库自增或全局唯一';
COMMENT ON COLUMN "public"."sso_users"."sub" IS 'IDaaS用户唯一标识(身份证号级别)';
COMMENT ON COLUMN "public"."sso_users"."username" IS '显示用户名称/工号';
COMMENT ON COLUMN "public"."sso_users"."nick_name" IS '用户真实姓名';
COMMENT ON COLUMN "public"."sso_users"."phone_number" IS '手机号';
COMMENT ON COLUMN "public"."sso_users"."email" IS '邮箱地址(可为空)';
COMMENT ON COLUMN "public"."sso_users"."ou_id" IS '所属组织单位ID(部门ID)';
COMMENT ON COLUMN "public"."sso_users"."ou_name" IS '所属部门名称';
COMMENT ON COLUMN "public"."sso_users"."status" IS '账户状态: 0=正常, 1=禁用';
COMMENT ON COLUMN "public"."sso_users"."is_leader" IS '是否为部门负责人';
COMMENT ON COLUMN "public"."sso_users"."created_at" IS '创建时间';
COMMENT ON COLUMN "public"."sso_users"."updated_at" IS '更新时间';
COMMENT ON COLUMN "public"."sso_users"."deleted_at" IS '删除时间(软删除)';
COMMENT ON TABLE "public"."sso_users" IS '统一登录用户表';

-- ----------------------------
-- Indexes structure for table sso_users
-- ----------------------------
CREATE INDEX "idx_sso_users_deleted_at" ON "public"."sso_users" USING btree (
  "deleted_at" "pg_catalog"."timestamp_ops" ASC NULLS LAST
);
CREATE INDEX "idx_sso_users_is_leader" ON "public"."sso_users" USING btree (
  "is_leader" "pg_catalog"."bool_ops" ASC NULLS LAST
);
CREATE INDEX "idx_sso_users_ou_id" ON "public"."sso_users" USING btree (
  "ou_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "idx_sso_users_status" ON "public"."sso_users" USING btree (
  "status" "pg_catalog"."int2_ops" ASC NULLS LAST
);
CREATE INDEX "idx_sso_users_sub" ON "public"."sso_users" USING btree (
  "sub" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "idx_sso_users_username" ON "public"."sso_users" USING btree (
  "username" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);

-- ----------------------------
-- Uniques structure for table sso_users
-- ----------------------------
ALTER TABLE "public"."sso_users" ADD CONSTRAINT "sso_users_sub_key" UNIQUE ("sub");

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