summaryrefslogtreecommitdiff
path: root/db/migrations/0010_big_sue_storm.sql
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrations/0010_big_sue_storm.sql')
-rw-r--r--db/migrations/0010_big_sue_storm.sql92
1 files changed, 92 insertions, 0 deletions
diff --git a/db/migrations/0010_big_sue_storm.sql b/db/migrations/0010_big_sue_storm.sql
new file mode 100644
index 00000000..572b3c11
--- /dev/null
+++ b/db/migrations/0010_big_sue_storm.sql
@@ -0,0 +1,92 @@
+CREATE TABLE "rfq_attachments" (
+ "id" serial PRIMARY KEY NOT NULL,
+ "rfq_id" integer,
+ "vendor_id" integer,
+ "file_name" varchar(255) NOT NULL,
+ "file_path" varchar(1024) NOT NULL,
+ "evaluation_id" integer,
+ "created_at" timestamp DEFAULT now() NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "rfq_comments" (
+ "id" serial PRIMARY KEY NOT NULL,
+ "rfq_id" integer,
+ "vendor_id" integer,
+ "comment_text" text NOT NULL,
+ "commented_by" integer NOT NULL,
+ "evaluation_id" integer,
+ "created_at" timestamp DEFAULT now() NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "rfq_evaluations" (
+ "id" serial PRIMARY KEY NOT NULL,
+ "rfq_id" integer NOT NULL,
+ "vendor_id" integer NOT NULL,
+ "eval_type" varchar(30),
+ "result" varchar(255),
+ "notes" text,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "updated_at" timestamp DEFAULT now() NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "rfq_items" (
+ "id" serial PRIMARY KEY NOT NULL,
+ "rfq_id" integer NOT NULL,
+ "item_code" varchar(100) NOT NULL,
+ "item_name" varchar(255) NOT NULL,
+ "description" text,
+ "quantity" numeric(12, 2) DEFAULT '1',
+ "uom" varchar(50),
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "updated_at" timestamp DEFAULT now() NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "rfq_vendors" (
+ "id" serial PRIMARY KEY NOT NULL,
+ "rfq_id" integer NOT NULL,
+ "vendor_id" integer NOT NULL,
+ "status" varchar(30) DEFAULT 'INVITED' NOT NULL,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "updated_at" timestamp DEFAULT now() NOT NULL
+);
+--> statement-breakpoint
+CREATE TABLE "rfqs" (
+ "id" serial PRIMARY KEY NOT NULL,
+ "rfq_code" varchar(50),
+ "project_code" varchar(50),
+ "project_name" varchar(255),
+ "due_date" date,
+ "status" varchar(30) DEFAULT 'DRAFT' NOT NULL,
+ "created_by" integer NOT NULL,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "updated_at" timestamp DEFAULT now() NOT NULL,
+ CONSTRAINT "rfqs_rfq_code_unique" UNIQUE("rfq_code")
+);
+--> statement-breakpoint
+CREATE TABLE "vendor_quotes" (
+ "id" serial PRIMARY KEY NOT NULL,
+ "rfq_id" integer NOT NULL,
+ "vendor_id" integer NOT NULL,
+ "total_amount" numeric(18, 2),
+ "currency" varchar(10) DEFAULT 'USD',
+ "lead_time" varchar(100),
+ "notes" text,
+ "created_at" timestamp DEFAULT now() NOT NULL,
+ "updated_at" timestamp DEFAULT now() NOT NULL
+);
+--> statement-breakpoint
+ALTER TABLE "rfq_attachments" ADD CONSTRAINT "rfq_attachments_rfq_id_rfqs_id_fk" FOREIGN KEY ("rfq_id") REFERENCES "public"."rfqs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "rfq_attachments" ADD CONSTRAINT "rfq_attachments_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "rfq_attachments" ADD CONSTRAINT "rfq_attachments_evaluation_id_rfq_evaluations_id_fk" FOREIGN KEY ("evaluation_id") REFERENCES "public"."rfq_evaluations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "rfq_comments" ADD CONSTRAINT "rfq_comments_rfq_id_rfqs_id_fk" FOREIGN KEY ("rfq_id") REFERENCES "public"."rfqs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "rfq_comments" ADD CONSTRAINT "rfq_comments_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "rfq_comments" ADD CONSTRAINT "rfq_comments_evaluation_id_rfq_evaluations_id_fk" FOREIGN KEY ("evaluation_id") REFERENCES "public"."rfq_evaluations"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "rfq_evaluations" ADD CONSTRAINT "rfq_evaluations_rfq_id_rfqs_id_fk" FOREIGN KEY ("rfq_id") REFERENCES "public"."rfqs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "rfq_evaluations" ADD CONSTRAINT "rfq_evaluations_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "rfq_items" ADD CONSTRAINT "rfq_items_rfq_id_rfqs_id_fk" FOREIGN KEY ("rfq_id") REFERENCES "public"."rfqs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "rfq_vendors" ADD CONSTRAINT "rfq_vendors_rfq_id_rfqs_id_fk" FOREIGN KEY ("rfq_id") REFERENCES "public"."rfqs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "rfq_vendors" ADD CONSTRAINT "rfq_vendors_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "vendor_quotes" ADD CONSTRAINT "vendor_quotes_rfq_id_rfqs_id_fk" FOREIGN KEY ("rfq_id") REFERENCES "public"."rfqs"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+ALTER TABLE "vendor_quotes" ADD CONSTRAINT "vendor_quotes_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
+CREATE UNIQUE INDEX "rfq_vendors_unique_rfqs" ON "rfq_vendors" USING btree ("rfq_id","vendor_id");--> statement-breakpoint
+CREATE UNIQUE INDEX "uq_vendor_quotes" ON "vendor_quotes" USING btree ("rfq_id","vendor_id"); \ No newline at end of file