CREATE TABLE "public"."t_crawler_book" (
  "book_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "book_name" varchar(255) COLLATE "pg_catalog"."default",
  "scheme_id" varchar(255) COLLATE "pg_catalog"."default",
  "subject_id" varchar(255) COLLATE "pg_catalog"."default",
  "stage_id" varchar(255) COLLATE "pg_catalog"."default",
  "id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL
)
;
COMMENT ON COLUMN "public"."t_crawler_book"."book_id" IS '册ID';
COMMENT ON COLUMN "public"."t_crawler_book"."book_name" IS '册的名称';
COMMENT ON COLUMN "public"."t_crawler_book"."scheme_id" IS '版本ID，比如人教版本ID,与t_crawler_scheme表中的scheme_id关联';
COMMENT ON COLUMN "public"."t_crawler_book"."subject_id" IS '科目id,与t_crawler_subject中的subject_id关联';
COMMENT ON COLUMN "public"."t_crawler_book"."stage_id" IS '学段ID，与t_crawler_stage中的stage_id关联';
COMMENT ON COLUMN "public"."t_crawler_book"."id" IS '主键，无实际意义';
COMMENT ON TABLE "public"."t_crawler_book" IS '课程章节目录中的册概念，比如三年级上册，四年级下册';

DROP TABLE IF EXISTS "public"."t_crawler_scheme";
CREATE TABLE "public"."t_crawler_scheme" (
  "scheme_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "scheme_name" varchar(255) COLLATE "pg_catalog"."default",
  "subject_id" varchar(255) COLLATE "pg_catalog"."default",
  "stage_id" varchar(255) COLLATE "pg_catalog"."default",
  "id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL
)
;
COMMENT ON COLUMN "public"."t_crawler_scheme"."scheme_id" IS '版本ID';
COMMENT ON COLUMN "public"."t_crawler_scheme"."scheme_name" IS '版本名称';
COMMENT ON COLUMN "public"."t_crawler_scheme"."subject_id" IS '学科ID';
COMMENT ON COLUMN "public"."t_crawler_scheme"."stage_id" IS '学段ID';
COMMENT ON COLUMN "public"."t_crawler_scheme"."id" IS '主键';
COMMENT ON TABLE "public"."t_crawler_scheme" IS '教材版本，目前一般一个学科一个版本';

DROP TABLE IF EXISTS "public"."t_crawler_stage";
CREATE TABLE "public"."t_crawler_stage" (
  "stage_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "stage_name" varchar(255) COLLATE "pg_catalog"."default"
)
;
COMMENT ON COLUMN "public"."t_crawler_stage"."stage_id" IS '学段ID';
COMMENT ON COLUMN "public"."t_crawler_stage"."stage_name" IS '学段名称';
COMMENT ON TABLE "public"."t_crawler_stage" IS '学段表';

DROP TABLE IF EXISTS "public"."t_crawler_subject";
CREATE TABLE "public"."t_crawler_subject" (
  "subject_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "subject_name" varchar(255) COLLATE "pg_catalog"."default",
  "stage_id" varchar(255) COLLATE "pg_catalog"."default"
)
;
COMMENT ON COLUMN "public"."t_crawler_subject"."subject_id" IS '科目ID';
COMMENT ON COLUMN "public"."t_crawler_subject"."subject_name" IS '科目名称';
COMMENT ON COLUMN "public"."t_crawler_subject"."stage_id" IS '学段ID';
COMMENT ON TABLE "public"."t_crawler_subject" IS '学科表';

ALTER TABLE "public"."t_crawler_book" ADD CONSTRAINT "t_crawler_booke_pkey" PRIMARY KEY ("id");

ALTER TABLE "public"."t_crawler_scheme" ADD CONSTRAINT "t_crawler_scheme_pkey" PRIMARY KEY ("id");


ALTER TABLE "public"."t_crawler_subject" ADD CONSTRAINT "t_crawler_subject_pkey" PRIMARY KEY ("subject_id");


DROP TABLE IF EXISTS "public"."t_crawler_lesson";
CREATE TABLE "public"."t_crawler_lesson" (
  "lesson_id" varchar(255) COLLATE "pg_catalog"."default",
  "lesson_name" varchar(255) COLLATE "pg_catalog"."default",
  "node_id" varchar(255) COLLATE "pg_catalog"."default",
  "teacher_id" varchar(255) COLLATE "pg_catalog"."default",
  "teacher_name" varchar(255) COLLATE "pg_catalog"."default",
  "teacher_school_id" varchar(255) COLLATE "pg_catalog"."default",
  "teacher_school_name" varchar(255) COLLATE "pg_catalog"."default",
  "id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "book_id" varchar(255) COLLATE "pg_catalog"."default",
  "scheme_id" varchar(255) COLLATE "pg_catalog"."default",
  "subject_id" varchar(255) COLLATE "pg_catalog"."default",
  "stage_id" varchar(255) COLLATE "pg_catalog"."default",
  "preview_count" int4 DEFAULT 0,
  "learning_person_count" int4 DEFAULT 0,
  "learning_person_times" int4 DEFAULT 0,
  "grade_code" varchar(255) COLLATE "pg_catalog"."default",
  "publish_time" date,
  "node_type" int2 DEFAULT 1
)
;
COMMENT ON COLUMN "public"."t_crawler_lesson"."lesson_id" IS '课程ID';
COMMENT ON COLUMN "public"."t_crawler_lesson"."lesson_name" IS '课程名称';
COMMENT ON COLUMN "public"."t_crawler_lesson"."node_id" IS '隶属哪个章节目录节点，关联t_crawler_structure中的node_id';
COMMENT ON COLUMN "public"."t_crawler_lesson"."teacher_id" IS '教师ID';
COMMENT ON COLUMN "public"."t_crawler_lesson"."teacher_name" IS '教师姓名';
COMMENT ON COLUMN "public"."t_crawler_lesson"."teacher_school_id" IS '教师学校ID,这个无用，处理关联学校时，使用t_crawler_lesson_school表';
COMMENT ON COLUMN "public"."t_crawler_lesson"."teacher_school_name" IS '教师学校名称,这个无用，处理关联学校时，使用t_crawler_lesson_school中数据';
COMMENT ON COLUMN "public"."t_crawler_lesson"."id" IS '主键';
COMMENT ON COLUMN "public"."t_crawler_lesson"."book_id" IS '册ID';
COMMENT ON COLUMN "public"."t_crawler_lesson"."scheme_id" IS '版本ID';
COMMENT ON COLUMN "public"."t_crawler_lesson"."preview_count" IS '预览次数';
COMMENT ON COLUMN "public"."t_crawler_lesson"."learning_person_count" IS '学习人数';
COMMENT ON COLUMN "public"."t_crawler_lesson"."learning_person_times" IS '学习人次';
COMMENT ON COLUMN "public"."t_crawler_lesson"."grade_code" IS '学段代码';
COMMENT ON COLUMN "public"."t_crawler_lesson"."publish_time" IS '发布时间';
COMMENT ON COLUMN "public"."t_crawler_lesson"."node_type" IS '节点类型 1：章节目录 2：知识点';
COMMENT ON TABLE "public"."t_crawler_lesson" IS '课程，resource资源表';

DROP TABLE IF EXISTS "public"."t_crawler_lesson_school";
CREATE TABLE "public"."t_crawler_lesson_school" (
  "lesson_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "original_school_name" varchar(255) COLLATE "pg_catalog"."default",
  "organization_name" varchar(255) COLLATE "pg_catalog"."default",
  "match_type" int4,
  "organization_no" varchar(255) COLLATE "pg_catalog"."default",
  "gather_regionc" varchar(255) COLLATE "pg_catalog"."default",
  "teacher_name" varchar(255) COLLATE "pg_catalog"."default",
  "update_ts" timestamp(6) DEFAULT now(),
  "school_running_type" varchar(255) COLLATE "pg_catalog"."default"
)
;
COMMENT ON COLUMN "public"."t_crawler_lesson_school"."lesson_id" IS '资源ID，通过资源ID与t_crawler_lesson中lesson_id关联，所有资源的学校、教师信息以本表为准';
COMMENT ON COLUMN "public"."t_crawler_lesson_school"."original_school_name" IS '原学校名称';
COMMENT ON COLUMN "public"."t_crawler_lesson_school"."organization_name" IS '正式学校名称';
COMMENT ON COLUMN "public"."t_crawler_lesson_school"."match_type" IS '0：未处理 1：名称完全一至 2：手工对应名称';
COMMENT ON COLUMN "public"."t_crawler_lesson_school"."organization_no" IS '正式学校代码';
COMMENT ON COLUMN "public"."t_crawler_lesson_school"."gather_regionc" IS '隶属行政区域名称';
COMMENT ON COLUMN "public"."t_crawler_lesson_school"."teacher_name" IS '教师名称';
COMMENT ON COLUMN "public"."t_crawler_lesson_school"."update_ts" IS '修改时间';
COMMENT ON COLUMN "public"."t_crawler_lesson_school"."school_running_type" IS '学校类型';
COMMENT ON TABLE "public"."t_crawler_lesson_school" IS '资源所属学校的原名和正式名对应表';

-- ----------------------------
-- Indexes structure for table t_crawler_lesson_school
-- ----------------------------
CREATE INDEX "idx_lesson_school_lesson" ON "public"."t_crawler_lesson_school" USING btree (
  "lesson_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "idx_lesson_school_match" ON "public"."t_crawler_lesson_school" USING btree (
  "match_type" "pg_catalog"."int4_ops" ASC NULLS LAST,
  "school_running_type" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "t_crawler_lesson_school_gather_regionc_idx" ON "public"."t_crawler_lesson_school" USING btree (
  "gather_regionc" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "t_crawler_lesson_school_lesson_id_match_type_idx" ON "public"."t_crawler_lesson_school" USING btree (
  "lesson_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "match_type" "pg_catalog"."int4_ops" ASC NULLS LAST
);
CREATE INDEX "t_crawler_lesson_school_match_type_idx" ON "public"."t_crawler_lesson_school" USING btree (
  "match_type" "pg_catalog"."int4_ops" ASC NULLS LAST
);

-- ----------------------------
-- Primary Key structure for table t_crawler_lesson_school
-- ----------------------------
ALTER TABLE "public"."t_crawler_lesson_school" ADD CONSTRAINT "t_crawler_school________pkey" PRIMARY KEY ("lesson_id");

DROP TABLE IF EXISTS "public"."t_crawler_structure";
CREATE TABLE "public"."t_crawler_structure" (
  "node_id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "node_name" varchar(255) COLLATE "pg_catalog"."default",
  "parent_id" varchar(255) COLLATE "pg_catalog"."default",
  "is_leaf" int2,
  "book_id" varchar(255) COLLATE "pg_catalog"."default",
  "scheme_id" varchar(255) COLLATE "pg_catalog"."default",
  "subject_id" varchar(255) COLLATE "pg_catalog"."default",
  "stage_id" varchar(255) COLLATE "pg_catalog"."default",
  "id" varchar(255) COLLATE "pg_catalog"."default" NOT NULL
)
;
COMMENT ON COLUMN "public"."t_crawler_structure"."node_id" IS '章节目录结点ID';
COMMENT ON COLUMN "public"."t_crawler_structure"."node_name" IS '章节目录结点名称';
COMMENT ON COLUMN "public"."t_crawler_structure"."parent_id" IS '章节目录父结点ID';
COMMENT ON COLUMN "public"."t_crawler_structure"."is_leaf" IS '是不是叶子节点';
COMMENT ON COLUMN "public"."t_crawler_structure"."book_id" IS '哪一册，关联t_crawler_book表中的book_id';
COMMENT ON COLUMN "public"."t_crawler_structure"."scheme_id" IS '版本ID，关联t_crawler_scheme的scheme_id';
COMMENT ON COLUMN "public"."t_crawler_structure"."subject_id" IS '科目ID，关联t_crawler_subject中的subject_id';
COMMENT ON COLUMN "public"."t_crawler_structure"."stage_id" IS '学段ID,关联t_crawler_stage中的stage_id';
COMMENT ON COLUMN "public"."t_crawler_structure"."id" IS '主键';
COMMENT ON TABLE "public"."t_crawler_structure" IS 'stage-subject-scheme-book-structure-resource';

DROP TABLE IF EXISTS "public"."t_crawler_structure_knowledge";
CREATE TABLE "public"."t_crawler_structure_knowledge" (
  "id" int4 NOT NULL DEFAULT nextval('t_crawler_structure_knowledge_id_seq'::regclass),
  "title" varchar(255) COLLATE "pg_catalog"."default" NOT NULL,
  "parent_id" varchar(50) COLLATE "pg_catalog"."default",
  "is_leaf" bool,
  "node_id" varchar(50) COLLATE "pg_catalog"."default",
  "sort" int4,
  "stage_id" varchar(10) COLLATE "pg_catalog"."default",
  "stage_name" varchar(50) COLLATE "pg_catalog"."default",
  "subject_id" varchar(10) COLLATE "pg_catalog"."default",
  "subject_name" varchar(50) COLLATE "pg_catalog"."default",
  "created_at" timestamp(6) DEFAULT CURRENT_TIMESTAMP
)
;
COMMENT ON COLUMN "public"."t_crawler_structure_knowledge"."id" IS '主键';
COMMENT ON COLUMN "public"."t_crawler_structure_knowledge"."title" IS '知识点名称';
COMMENT ON COLUMN "public"."t_crawler_structure_knowledge"."parent_id" IS '父ID';
COMMENT ON COLUMN "public"."t_crawler_structure_knowledge"."is_leaf" IS '是不是叶子';
COMMENT ON COLUMN "public"."t_crawler_structure_knowledge"."node_id" IS '知识点ID';
COMMENT ON COLUMN "public"."t_crawler_structure_knowledge"."sort" IS '排序号';
COMMENT ON COLUMN "public"."t_crawler_structure_knowledge"."stage_id" IS '学段ID';
COMMENT ON COLUMN "public"."t_crawler_structure_knowledge"."stage_name" IS '学段名称';
COMMENT ON COLUMN "public"."t_crawler_structure_knowledge"."subject_id" IS '科目ID';
COMMENT ON COLUMN "public"."t_crawler_structure_knowledge"."subject_name" IS '科目名称';


CREATE INDEX "idx_lesson_publish_subject" ON "public"."t_crawler_lesson" USING btree (
  "publish_time" "pg_catalog"."date_ops" ASC NULLS LAST,
  "subject_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "t_crawler_lesson_node_type_idx" ON "public"."t_crawler_lesson" USING btree (
  "node_type" "pg_catalog"."int2_ops" ASC NULLS LAST
);


ALTER TABLE "public"."t_crawler_lesson" ADD CONSTRAINT "t_crawler_resource_pkey" PRIMARY KEY ("id");


CREATE INDEX "idx_lesson_school_lesson" ON "public"."t_crawler_lesson_school" USING btree (
  "lesson_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "idx_lesson_school_match" ON "public"."t_crawler_lesson_school" USING btree (
  "match_type" "pg_catalog"."int4_ops" ASC NULLS LAST,
  "school_running_type" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "t_crawler_lesson_school_gather_regionc_idx" ON "public"."t_crawler_lesson_school" USING btree (
  "gather_regionc" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "t_crawler_lesson_school_lesson_id_match_type_idx" ON "public"."t_crawler_lesson_school" USING btree (
  "lesson_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
  "match_type" "pg_catalog"."int4_ops" ASC NULLS LAST
);
CREATE INDEX "t_crawler_lesson_school_match_type_idx" ON "public"."t_crawler_lesson_school" USING btree (
  "match_type" "pg_catalog"."int4_ops" ASC NULLS LAST
);


ALTER TABLE "public"."t_crawler_lesson_school" ADD CONSTRAINT "t_crawler_school________pkey" PRIMARY KEY ("lesson_id");


ALTER TABLE "public"."t_crawler_structure" ADD CONSTRAINT "t_crawler_structure_pkey" PRIMARY KEY ("id");

ALTER TABLE "public"."t_crawler_structure_knowledge" ADD CONSTRAINT "t_crawler_structure_knowledge_pkey" PRIMARY KEY ("id");
