diff options
Diffstat (limited to 'db/migrations/0153_puzzling_darkstar.sql')
| -rw-r--r-- | db/migrations/0153_puzzling_darkstar.sql | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/db/migrations/0153_puzzling_darkstar.sql b/db/migrations/0153_puzzling_darkstar.sql new file mode 100644 index 00000000..c7203868 --- /dev/null +++ b/db/migrations/0153_puzzling_darkstar.sql @@ -0,0 +1,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;
\ No newline at end of file |
