/*
 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: 16/07/2025 21:59:28
*/


-- ----------------------------
-- Table structure for scoring_proposals
-- ----------------------------
DROP TABLE IF EXISTS "public"."scoring_proposals";
CREATE TABLE "public"."scoring_proposals" (
  "id" int4 NOT NULL DEFAULT nextval('scoring_proposals_id_seq'::regclass),
  "evaluation_result_id" int4 NOT NULL,
  "proposer_id" int4 NOT NULL,
  "proposed_score" numeric(10,2) NOT NULL,
  "reason" text COLLATE "pg_catalog"."default" NOT NULL,
  "status" varchar(50) COLLATE "pg_catalog"."default" NOT NULL DEFAULT 'pending_review'::character varying,
  "created_at" timestamptz(6) NOT NULL DEFAULT now(),
  "updated_at" timestamptz(6) NOT NULL DEFAULT now(),
  "document_id" int4 NOT NULL
)
;
COMMENT ON COLUMN "public"."scoring_proposals"."id" IS '计分提案的唯一标识符。';
COMMENT ON COLUMN "public"."scoring_proposals"."evaluation_result_id" IS '关联的评查结果ID，外键引用 evaluation_results 表。';
COMMENT ON COLUMN "public"."scoring_proposals"."proposer_id" IS '提出提案的用户ID，外键引用 users 表。';
COMMENT ON COLUMN "public"."scoring_proposals"."proposed_score" IS '提案中建议的修正分数。';
COMMENT ON COLUMN "public"."scoring_proposals"."reason" IS '修改分数的理由说明。';
COMMENT ON COLUMN "public"."scoring_proposals"."status" IS '提案的当前状态：待审核、已批准或已否决。';
COMMENT ON COLUMN "public"."scoring_proposals"."created_at" IS '提案创建的时间戳。';
COMMENT ON COLUMN "public"."scoring_proposals"."updated_at" IS '提案最后更新的时间戳。';
COMMENT ON COLUMN "public"."scoring_proposals"."document_id" IS '关联的文档ID，用于快速查询和统计';
COMMENT ON TABLE "public"."scoring_proposals" IS '存储用户对评查结果提出的计分修改提案。';

-- ----------------------------
-- Indexes structure for table scoring_proposals
-- ----------------------------
CREATE INDEX "idx_scoring_proposals_document_id" ON "public"."scoring_proposals" USING btree (
  "document_id" "pg_catalog"."int4_ops" ASC NULLS LAST
);
CREATE INDEX "idx_scoring_proposals_document_status" ON "public"."scoring_proposals" USING btree (
  "document_id" "pg_catalog"."int4_ops" ASC NULLS LAST,
  "status" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX "idx_scoring_proposals_evaluation_result_id" ON "public"."scoring_proposals" USING btree (
  "evaluation_result_id" "pg_catalog"."int4_ops" ASC NULLS LAST
);
CREATE INDEX "idx_scoring_proposals_proposer_id" ON "public"."scoring_proposals" USING btree (
  "proposer_id" "pg_catalog"."int4_ops" ASC NULLS LAST
);
CREATE UNIQUE INDEX "uq_pending_proposal" ON "public"."scoring_proposals" USING btree (
  "evaluation_result_id" "pg_catalog"."int4_ops" ASC NULLS LAST
) WHERE status::text = 'pending_review'::text;

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

-- ----------------------------
-- Foreign Keys structure for table scoring_proposals
-- ----------------------------
ALTER TABLE "public"."scoring_proposals" ADD CONSTRAINT "scoring_proposals_evaluation_result_id_fkey" FOREIGN KEY ("evaluation_result_id") REFERENCES "public"."evaluation_results" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
ALTER TABLE "public"."scoring_proposals" ADD CONSTRAINT "scoring_proposals_proposer_id_fkey" FOREIGN KEY ("proposer_id") REFERENCES "public"."users" ("id") ON DELETE CASCADE ON UPDATE NO ACTION;
