-- ----------------------------
-- Table structure for kb_attachment
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_attachment";
CREATE TABLE "public"."kb_attachment"
(
    "attachment_name" varchar COLLATE "pg_catalog"."default",
    "attachment_path" varchar COLLATE "pg_catalog"."default",
    "create_time"     int4,
    "create_by_id"    varchar COLLATE "pg_catalog"."default",
    "id"              int8
)
;
COMMENT
ON COLUMN "public"."kb_attachment"."attachment_name" IS '附件名';
COMMENT
ON COLUMN "public"."kb_attachment"."attachment_path" IS '附件路径 不到host 例如 /20240301/uthjkksjhlgl.jpg?xxx';
COMMENT
ON COLUMN "public"."kb_attachment"."create_by_id" IS '上传附件的人id';
COMMENT
ON TABLE "public"."kb_attachment" IS '附件表';

-- ----------------------------
-- Table structure for kb_base
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_base";
CREATE TABLE "public"."kb_base"
(
    "id"              int8 NOT NULL,
    "base_name"       varchar COLLATE "pg_catalog"."default",
    "create_time"     int4,
    "create_by_id"    varchar COLLATE "pg_catalog"."default",
    "create_by_name"  varchar COLLATE "pg_catalog"."default",
    "dept_id"         varchar COLLATE "pg_catalog"."default",
    "is_public"       int4,
    "update_by_id"    varchar COLLATE "pg_catalog"."default",
    "update_by_name"  varchar COLLATE "pg_catalog"."default",
    "update_time"     int4,
    "category_count"  int8,
    "knowledge_count" int8,
    "dept_name"       varchar COLLATE "pg_catalog"."default"
)
;
COMMENT
ON COLUMN "public"."kb_base"."base_name" IS '库名';
COMMENT
ON COLUMN "public"."kb_base"."dept_id" IS '部门id';
COMMENT
ON COLUMN "public"."kb_base"."is_public" IS '是否公开 0 非公开 1 公开';
COMMENT
ON TABLE "public"."kb_base" IS '库';

-- ----------------------------
-- Table structure for kb_browse_history
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_browse_history";
CREATE TABLE "public"."kb_browse_history"
(
    "id"           int8 NOT NULL,
    "user_id"      varchar COLLATE "pg_catalog"."default",
    "knowledge_id" int8,
    "create_time"  int4
)
;
COMMENT
ON TABLE "public"."kb_browse_history" IS '浏览历史';

-- ----------------------------
-- Table structure for kb_category
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_category";
CREATE TABLE "public"."kb_category"
(
    "id"                 int8 NOT NULL,
    "pid"                int8,
    "category_name"      varchar COLLATE "pg_catalog"."default",
    "create_time"        int4,
    "create_by_id"       varchar COLLATE "pg_catalog"."default",
    "update_time"        int4,
    "update_by_id"       varchar COLLATE "pg_catalog"."default",
    "kb_count"           int4,
    "base_id"            int8,
    "category_full_name" varchar COLLATE "pg_catalog"."default"
)
;
COMMENT
ON COLUMN "public"."kb_category"."pid" IS '父级id';
COMMENT
ON COLUMN "public"."kb_category"."category_name" IS '分类名字';
COMMENT
ON COLUMN "public"."kb_category"."create_time" IS '创建时间';
COMMENT
ON COLUMN "public"."kb_category"."create_by_id" IS '创建id';
COMMENT
ON COLUMN "public"."kb_category"."update_time" IS '更新时间';
COMMENT
ON COLUMN "public"."kb_category"."update_by_id" IS '更新id';
COMMENT
ON COLUMN "public"."kb_category"."kb_count" IS '知识数量';
COMMENT
ON COLUMN "public"."kb_category"."base_id" IS '库id';
COMMENT
ON COLUMN "public"."kb_category"."category_full_name" IS '分类串';
COMMENT
ON TABLE "public"."kb_category" IS '分类表';

-- ----------------------------
-- Table structure for kb_ik
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_ik";
CREATE TABLE "public"."kb_ik"
(
    "id"                int8 NOT NULL,
    "user_id"           varchar COLLATE "pg_catalog"."default",
    "user_name"         varchar COLLATE "pg_catalog"."default",
    "word"              varchar COLLATE "pg_catalog"."default",
    "create_time"       int4,
    "browse_history_id" int8
)
;
COMMENT
ON COLUMN "public"."kb_ik"."user_name" IS '用户名';
COMMENT
ON COLUMN "public"."kb_ik"."word" IS '分词结果';
COMMENT
ON COLUMN "public"."kb_ik"."browse_history_id" IS '搜索历史的id';
COMMENT
ON TABLE "public"."kb_ik" IS '搜索的分词表, 便于以后做智能推荐';

-- ----------------------------
-- Table structure for kb_knowledge
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_knowledge";
CREATE TABLE "public"."kb_knowledge"
(
    "id"              int8 NOT NULL,
    "title"           varchar(255) COLLATE "pg_catalog"."default",
    "description"     varchar(255) COLLATE "pg_catalog"."default",
    "category_id"     int8,
    "create_time"     int4,
    "create_by_id"    varchar COLLATE "pg_catalog"."default",
    "create_by_name"  varchar(255) COLLATE "pg_catalog"."default",
    "update_time"     int4,
    "update_by_id"    varchar COLLATE "pg_catalog"."default",
    "update_by_name"  varchar COLLATE "pg_catalog"."default",
    "is_text"         int4 DEFAULT 0,
    "is_image"        int4 DEFAULT 0,
    "is_doc"          int4 DEFAULT 0,
    "is_video"        int4 DEFAULT 0,
    "is_publish"      int4 DEFAULT 0,
    "collection_num"  int4 DEFAULT 0,
    "view_num"        int4 DEFAULT 0,
    "base_id"         int8,
    "attachment_type" varchar COLLATE "pg_catalog"."default",
    "resource"        varchar COLLATE "pg_catalog"."default",
    "publish_time"    int4,
    "implement_time"  int4,
    "comment_num"     int8,
    "is_public"       int4,
    "attachment_path" varchar COLLATE "pg_catalog"."default"
)
;
COMMENT
ON COLUMN "public"."kb_knowledge"."title" IS '标题';
COMMENT
ON COLUMN "public"."kb_knowledge"."description" IS '摘要';
COMMENT
ON COLUMN "public"."kb_knowledge"."category_id" IS '分类id';
COMMENT
ON COLUMN "public"."kb_knowledge"."create_time" IS '创建时间';
COMMENT
ON COLUMN "public"."kb_knowledge"."create_by_id" IS '创建者id';
COMMENT
ON COLUMN "public"."kb_knowledge"."create_by_name" IS '创建者姓名';
COMMENT
ON COLUMN "public"."kb_knowledge"."update_time" IS '更新时间';
COMMENT
ON COLUMN "public"."kb_knowledge"."update_by_id" IS '更新者id';
COMMENT
ON COLUMN "public"."kb_knowledge"."update_by_name" IS '更新者姓名';
COMMENT
ON COLUMN "public"."kb_knowledge"."is_text" IS '是否是文本类型 0 否 1 是';
COMMENT
ON COLUMN "public"."kb_knowledge"."is_image" IS '是否是图片类型 0 否 1 是';
COMMENT
ON COLUMN "public"."kb_knowledge"."is_doc" IS '是否是文档类型 0 否 1 是';
COMMENT
ON COLUMN "public"."kb_knowledge"."is_video" IS '是否是视频类型 0 否 1 是';
COMMENT
ON COLUMN "public"."kb_knowledge"."is_publish" IS '是否发布  0 未发布 1 已发布';
COMMENT
ON COLUMN "public"."kb_knowledge"."collection_num" IS '收藏量';
COMMENT
ON COLUMN "public"."kb_knowledge"."view_num" IS '浏览量';
COMMENT
ON COLUMN "public"."kb_knowledge"."attachment_type" IS '附件类型 pdf doc docx 等';
COMMENT
ON COLUMN "public"."kb_knowledge"."publish_time" IS '发布时间';
COMMENT
ON COLUMN "public"."kb_knowledge"."implement_time" IS '实施时间';
COMMENT
ON COLUMN "public"."kb_knowledge"."attachment_path" IS '附件路径';

-- ----------------------------
-- Table structure for kb_knowledge_attachment
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_knowledge_attachment";
CREATE TABLE "public"."kb_knowledge_attachment"
(
    "knowledge_id"  int8,
    "attachment_id" int8,
    "id"            bigserial
)
;

-- ----------------------------
-- Table structure for kb_knowledge_category
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_knowledge_category";
CREATE TABLE "public"."kb_knowledge_category"
(
    "id"           int8,
    "knowledge_id" int8,
    "category_id"  int8 NOT NULL
)
;
COMMENT
ON TABLE "public"."kb_knowledge_category" IS '知识的分类';

-- ----------------------------
-- Table structure for kb_knowledge_collection
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_knowledge_collection";
CREATE TABLE "public"."kb_knowledge_collection"
(
    "id"           int8 NOT NULL,
    "knowlegde_id" int8,
    "user_id"      varchar COLLATE "pg_catalog"."default",
    "create_time"  int4
)
;
COMMENT
ON TABLE "public"."kb_knowledge_collection" IS '个人收藏表';

-- ----------------------------
-- Table structure for kb_knowledge_comment
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_knowledge_comment";
CREATE TABLE "public"."kb_knowledge_comment"
(
    "id"             int8 NOT NULL,
    "comment"        varchar COLLATE "pg_catalog"."default",
    "knowledge_id"   int8,
    "create_time"    int4,
    "create_by_id"   varchar COLLATE "pg_catalog"."default",
    "create_by_name" varchar COLLATE "pg_catalog"."default",
    "update_time"    int4,
    "update_by_id"   varchar COLLATE "pg_catalog"."default",
    "update_by_name" varchar COLLATE "pg_catalog"."default"
)
;
COMMENT
ON COLUMN "public"."kb_knowledge_comment"."comment" IS '评论内容';
COMMENT
ON COLUMN "public"."kb_knowledge_comment"."knowledge_id" IS '知识id';
COMMENT
ON COLUMN "public"."kb_knowledge_comment"."create_time" IS '创建时间';
COMMENT
ON COLUMN "public"."kb_knowledge_comment"."create_by_id" IS '创建者id';
COMMENT
ON COLUMN "public"."kb_knowledge_comment"."create_by_name" IS '创建者姓名';
COMMENT
ON TABLE "public"."kb_knowledge_comment" IS '知识评论';

-- ----------------------------
-- Table structure for kb_knowledge_content
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_knowledge_content";
CREATE TABLE "public"."kb_knowledge_content"
(
    "knowledge_id"      int8,
    "knowledge_content" text COLLATE "pg_catalog"."default",
    "id"                bigserial
)
;
COMMENT
ON COLUMN "public"."kb_knowledge_content"."knowledge_id" IS '知识id';
COMMENT
ON COLUMN "public"."kb_knowledge_content"."knowledge_content" IS '知识内容';
COMMENT
ON TABLE "public"."kb_knowledge_content" IS '知识内容';

-- ----------------------------
-- Table structure for kb_knowledge_img
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_knowledge_img";
CREATE TABLE "public"."kb_knowledge_img"
(
    "knowledge_id" int8,
    "img_path"     varchar COLLATE "pg_catalog"."default",
    "id"           bigserial
)
;
COMMENT
ON TABLE "public"."kb_knowledge_img" IS '知识附件上传上来的pdf转的图片';

-- ----------------------------
-- Table structure for kb_knowledge_resource
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_knowledge_resource";
CREATE TABLE "public"."kb_knowledge_resource"
(
    "knowledge_id" int8,
    "resource_id"  int8,
    "id"           bigserial
)
;
COMMENT
ON COLUMN "public"."kb_knowledge_resource"."knowledge_id" IS '知识id';
COMMENT
ON COLUMN "public"."kb_knowledge_resource"."resource_id" IS '来源id';
COMMENT
ON TABLE "public"."kb_knowledge_resource" IS '知识来源表';

-- ----------------------------
-- Table structure for kb_knowledge_tag
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_knowledge_tag";
CREATE TABLE "public"."kb_knowledge_tag"
(
    "knowledge_id" int8,
    "tag_id"       int8,
    "id"           bigserial
)
;
COMMENT
ON COLUMN "public"."kb_knowledge_tag"."knowledge_id" IS '知识id';
COMMENT
ON COLUMN "public"."kb_knowledge_tag"."tag_id" IS '标签id';
COMMENT
ON TABLE "public"."kb_knowledge_tag" IS '知识的标签表';

-- ----------------------------
-- Table structure for kb_menu
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_menu";
CREATE TABLE "public"."kb_menu"
(
    "id"        int8 NOT NULL,
    "menu_name" varchar COLLATE "pg_catalog"."default",
    "menu_path" varchar COLLATE "pg_catalog"."default"
)
;
COMMENT
ON COLUMN "public"."kb_menu"."menu_name" IS '菜单名';
COMMENT
ON COLUMN "public"."kb_menu"."menu_path" IS '菜单路径';
COMMENT
ON TABLE "public"."kb_menu" IS '通过user_id查询菜单 前端展示这些菜单实现权限控制';

-- ----------------------------
-- Table structure for kb_resource
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_resource";
CREATE TABLE "public"."kb_resource"
(
    "id"             int8 NOT NULL,
    "resource_name"  varchar COLLATE "pg_catalog"."default",
    "create_time"    int4,
    "update_time"    int4,
    "create_by_id"   varchar COLLATE "pg_catalog"."default",
    "update_by_id"   varchar COLLATE "pg_catalog"."default",
    "create_by_name" varchar COLLATE "pg_catalog"."default",
    "update_by_name" varchar COLLATE "pg_catalog"."default"
)
;
COMMENT
ON COLUMN "public"."kb_resource"."resource_name" IS '来源名';
COMMENT
ON COLUMN "public"."kb_resource"."create_time" IS '创建时间';
COMMENT
ON COLUMN "public"."kb_resource"."update_time" IS '更新时间';
COMMENT
ON COLUMN "public"."kb_resource"."create_by_id" IS '创建者id';
COMMENT
ON COLUMN "public"."kb_resource"."update_by_id" IS '更新者id';
COMMENT
ON COLUMN "public"."kb_resource"."create_by_name" IS '创建者姓名';
COMMENT
ON COLUMN "public"."kb_resource"."update_by_name" IS '更新者姓名';
COMMENT
ON TABLE "public"."kb_resource" IS '来源表';

-- ----------------------------
-- Table structure for kb_search_history
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_search_history";
CREATE TABLE "public"."kb_search_history"
(
    "id"          int8 NOT NULL,
    "user_id"     varchar COLLATE "pg_catalog"."default",
    "user_name"   varchar COLLATE "pg_catalog"."default",
    "search_word" varchar COLLATE "pg_catalog"."default",
    "create_time" int4
)
;
COMMENT
ON COLUMN "public"."kb_search_history"."user_id" IS '用户id';
COMMENT
ON COLUMN "public"."kb_search_history"."user_name" IS '用户姓名';
COMMENT
ON COLUMN "public"."kb_search_history"."search_word" IS '搜索词';
COMMENT
ON COLUMN "public"."kb_search_history"."create_time" IS '创建时间';
COMMENT
ON TABLE "public"."kb_search_history" IS '搜索历史';

-- ----------------------------
-- Table structure for kb_tag
-- ----------------------------
DROP TABLE IF EXISTS "public"."kb_tag";
CREATE TABLE "public"."kb_tag"
(
    "id"             int8 NOT NULL,
    "tag_name"       varchar COLLATE "pg_catalog"."default",
    "create_time"    int4,
    "update_time"    int4,
    "create_by_id"   varchar COLLATE "pg_catalog"."default",
    "update_by_id"   varchar COLLATE "pg_catalog"."default",
    "create_by_name" varchar COLLATE "pg_catalog"."default",
    "update_by_name" varchar COLLATE "pg_catalog"."default"
)
;
COMMENT
ON COLUMN "public"."kb_tag"."tag_name" IS '标签名';
COMMENT
ON COLUMN "public"."kb_tag"."create_time" IS '创建时间';
COMMENT
ON COLUMN "public"."kb_tag"."update_time" IS '更新时间';
COMMENT
ON COLUMN "public"."kb_tag"."create_by_id" IS '创建者id';
COMMENT
ON COLUMN "public"."kb_tag"."update_by_id" IS '更新者id';
COMMENT
ON COLUMN "public"."kb_tag"."create_by_name" IS '创建者姓名';
COMMENT
ON COLUMN "public"."kb_tag"."update_by_name" IS '更新者姓名';
COMMENT
ON TABLE "public"."kb_tag" IS '标签表';

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

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

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

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

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

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

-- ----------------------------
-- Primary Key structure for table kb_knowledge_category
-- ----------------------------
ALTER TABLE "public"."kb_knowledge_category"
    ADD CONSTRAINT "kb_knowledge_category_pkey" PRIMARY KEY ("category_id");

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

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

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

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

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

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

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

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

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

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