DO $$ BEGIN
 CREATE TYPE "housing_type" AS ENUM('Private', 'Social');
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "scenario" (
	"id" bigserial PRIMARY KEY NOT NULL,
	"name" text,
	"budget" real,
	"portfolio_id" bigint NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL,
	"housing_type" "housing_type" NOT NULL,
	"goal" "goal" NOT NULL,
	"trigger_file_path" text,
	"already_installed_file_path" text,
	"patches_file_path" text,
	"non_invasive_recommendations_file_path" text,
	"exclusions" text,
	"multi_plan" boolean
);
--> statement-breakpoint
ALTER TABLE "plan" ADD COLUMN "scenario_id" bigint;--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "plan" ADD CONSTRAINT "plan_scenario_id_scenario_id_fk" FOREIGN KEY ("scenario_id") REFERENCES "scenario"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "scenario" ADD CONSTRAINT "scenario_portfolio_id_portfolio_id_fk" FOREIGN KEY ("portfolio_id") REFERENCES "portfolio"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
