summaryrefslogtreecommitdiff
path: root/db/migrations/0153_puzzling_darkstar.sql
blob: c7203868536adfe4b4ad96245c169753e25da0f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
CREATE TABLE "esg_evaluation_responses" (
	"id" serial PRIMARY KEY NOT NULL,
	"submission_id" integer NOT NULL,
	"esg_evaluation_item_id" integer NOT NULL,
	"esg_answer_option_id" integer NOT NULL,
	"selected_score" numeric(5, 2) NOT NULL,
	"additional_comments" text,
	"is_active" boolean DEFAULT true NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "evaluation_submissions" (
	"id" serial PRIMARY KEY NOT NULL,
	"submission_id" uuid DEFAULT gen_random_uuid() NOT NULL,
	"company_id" integer NOT NULL,
	"evaluation_year" integer NOT NULL,
	"evaluation_round" varchar(50),
	"submission_status" varchar(50) DEFAULT 'draft' NOT NULL,
	"submitted_at" timestamp,
	"reviewed_at" timestamp,
	"reviewed_by" varchar(100),
	"review_comments" text,
	"average_esg_score" numeric(5, 2),
	"total_general_items" integer DEFAULT 0,
	"completed_general_items" integer DEFAULT 0,
	"total_esg_items" integer DEFAULT 0,
	"completed_esg_items" integer DEFAULT 0,
	"is_active" boolean DEFAULT true NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "evaluation_submissions_submission_id_unique" UNIQUE("submission_id")
);
--> statement-breakpoint
CREATE TABLE "general_evaluation_responses" (
	"id" serial PRIMARY KEY NOT NULL,
	"submission_id" integer NOT NULL,
	"general_evaluation_id" integer NOT NULL,
	"response_text" text NOT NULL,
	"has_attachments" boolean DEFAULT false NOT NULL,
	"review_comments" text,
	"is_active" boolean DEFAULT true NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "vendor_evaluation_attachments" (
	"id" serial PRIMARY KEY NOT NULL,
	"file_id" uuid DEFAULT gen_random_uuid() NOT NULL,
	"submission_id" integer NOT NULL,
	"general_evaluation_response_id" integer,
	"original_file_name" varchar(500) NOT NULL,
	"stored_file_name" varchar(500) NOT NULL,
	"file_path" text NOT NULL,
	"file_size" integer NOT NULL,
	"mime_type" varchar(200),
	"uploaded_by" varchar(100) NOT NULL,
	"is_active" boolean DEFAULT true NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"updated_at" timestamp DEFAULT now() NOT NULL,
	CONSTRAINT "vendor_evaluation_attachments_file_id_unique" UNIQUE("file_id")
);
--> statement-breakpoint
ALTER TABLE "esg_evaluation_responses" ADD CONSTRAINT "esg_evaluation_responses_submission_id_evaluation_submissions_id_fk" FOREIGN KEY ("submission_id") REFERENCES "public"."evaluation_submissions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "esg_evaluation_responses" ADD CONSTRAINT "esg_evaluation_responses_esg_evaluation_item_id_esg_evaluation_items_id_fk" FOREIGN KEY ("esg_evaluation_item_id") REFERENCES "public"."esg_evaluation_items"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "esg_evaluation_responses" ADD CONSTRAINT "esg_evaluation_responses_esg_answer_option_id_esg_answer_options_id_fk" FOREIGN KEY ("esg_answer_option_id") REFERENCES "public"."esg_answer_options"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "evaluation_submissions" ADD CONSTRAINT "evaluation_submissions_company_id_vendors_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."vendors"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "general_evaluation_responses" ADD CONSTRAINT "general_evaluation_responses_submission_id_evaluation_submissions_id_fk" FOREIGN KEY ("submission_id") REFERENCES "public"."evaluation_submissions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "general_evaluation_responses" ADD CONSTRAINT "general_evaluation_responses_general_evaluation_id_general_evaluations_id_fk" FOREIGN KEY ("general_evaluation_id") REFERENCES "public"."general_evaluations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "vendor_evaluation_attachments" ADD CONSTRAINT "vendor_evaluation_attachments_submission_id_evaluation_submissions_id_fk" FOREIGN KEY ("submission_id") REFERENCES "public"."evaluation_submissions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "vendor_evaluation_attachments" ADD CONSTRAINT "vendor_evaluation_attachments_general_evaluation_response_id_general_evaluation_responses_id_fk" FOREIGN KEY ("general_evaluation_response_id") REFERENCES "public"."general_evaluation_responses"("id") ON DELETE cascade ON UPDATE no action;