CREATE TABLE IF NOT EXISTS "property_details_epc" (
	"id" serial PRIMARY KEY NOT NULL,
	"property_id" integer NOT NULL,
	"portfolio_id" integer NOT NULL,
	"full_address" text,
	"total_floor_area" real,
	"walls" text,
	"walls_rating" smallint,
	"roof" text,
	"roof_rating" smallint,
	"floor" text,
	"floor_rating" smallint,
	"windows" text,
	"windows_rating" smallint,
	"heating" text,
	"heating_rating" smallint,
	"heating_contols" text,
	"heating_contols_rating" smallint,
	"hot_water" text,
	"hot_water_rating" smallint,
	"lighting" text,
	"lighting_rating" smallint,
	"ventilation" text,
	"solar_pv" text,
	"solar_hot_water" text,
	"wind_turbine" text,
	"floor_height" real,
	"number_heated_rooms" integer,
	"heat_loss_corridor" boolean,
	"unheated_corridor_length" real,
	"number_of_open_fireplaces" integer,
	"number_of_extensions" integer,
	"number_of_storeys" integer,
	"mains_gas" boolean,
	"energy_tariff" text,
	"primary_energy_consumption" real,
	"co2_emissions" real
);
--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "property_details_epc" ADD CONSTRAINT "property_details_epc_property_id_property_id_fk" FOREIGN KEY ("property_id") REFERENCES "property"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
 ALTER TABLE "property_details_epc" ADD CONSTRAINT "property_details_epc_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 $$;
