42 lines
1.8 KiB
SQL
42 lines
1.8 KiB
SQL
CREATE TABLE IF NOT EXISTS "inspection_templates" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"org_id" text NOT NULL,
|
|
"category" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"steps" jsonb NOT NULL,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
);
|
|
|
|
CREATE TABLE IF NOT EXISTS "inspection_runs" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"org_id" text NOT NULL,
|
|
"template_id" uuid NOT NULL,
|
|
"offer_id" uuid,
|
|
"asset_id" uuid,
|
|
"status" text DEFAULT 'in_progress' NOT NULL,
|
|
"evidence_refs" jsonb,
|
|
"result_notes" text,
|
|
"completed_at" timestamp,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
);
|
|
|
|
ALTER TABLE "inspection_runs" ADD CONSTRAINT "inspection_runs_template_id_fk" FOREIGN KEY ("template_id") REFERENCES "public"."inspection_templates"("id");
|
|
ALTER TABLE "inspection_runs" ADD CONSTRAINT "inspection_runs_offer_id_fk" FOREIGN KEY ("offer_id") REFERENCES "public"."offers"("id");
|
|
ALTER TABLE "inspection_runs" ADD CONSTRAINT "inspection_runs_asset_id_fk" FOREIGN KEY ("asset_id") REFERENCES "public"."assets"("id");
|
|
|
|
CREATE TABLE IF NOT EXISTS "integration_mappings" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"org_id" text NOT NULL,
|
|
"asset_id" uuid,
|
|
"site_id" uuid,
|
|
"provider" text NOT NULL,
|
|
"external_id" text NOT NULL,
|
|
"metadata" jsonb,
|
|
"created_at" timestamp DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp DEFAULT now() NOT NULL
|
|
);
|
|
ALTER TABLE "integration_mappings" ADD CONSTRAINT "integration_mappings_asset_id_fk" FOREIGN KEY ("asset_id") REFERENCES "public"."assets"("id");
|
|
ALTER TABLE "integration_mappings" ADD CONSTRAINT "integration_mappings_site_id_fk" FOREIGN KEY ("site_id") REFERENCES "public"."sites"("id");
|