CREATE TABLE "position_covers" (
	"id" uuid PRIMARY KEY DEFAULT gen_random_uuid(),
	"position_id" uuid NOT NULL,
	"covering_person_id" uuid NOT NULL,
	"from_date" date NOT NULL,
	"until_date" date NOT NULL,
	"reason" text,
	"created_by" uuid NOT NULL,
	"created_at" timestamp with time zone DEFAULT now() NOT NULL,
	CONSTRAINT "position_covers_window_ordered" CHECK ("until_date" >= "from_date")
);
--> statement-breakpoint
CREATE INDEX "position_covers_position_idx" ON "position_covers" ("position_id");--> statement-breakpoint
ALTER TABLE "position_covers" ADD CONSTRAINT "position_covers_position_id_positions_id_fkey" FOREIGN KEY ("position_id") REFERENCES "positions"("id");--> statement-breakpoint
ALTER TABLE "position_covers" ADD CONSTRAINT "position_covers_covering_person_id_people_id_fkey" FOREIGN KEY ("covering_person_id") REFERENCES "people"("id");--> statement-breakpoint
ALTER TABLE "position_covers" ADD CONSTRAINT "position_covers_created_by_people_id_fkey" FOREIGN KEY ("created_by") REFERENCES "people"("id");