CREATE TABLE "area" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "slug" text NOT NULL, "name" text NOT NULL, "kind" text NOT NULL, "order" integer DEFAULT 0 NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "milestone" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "project_id" uuid NOT NULL, "title" text NOT NULL, "due" date, "status" text DEFAULT 'open' NOT NULL, "description" text, "order" integer DEFAULT 0 NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint CREATE TABLE "project" ( "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, "area_id" uuid NOT NULL, "name" text NOT NULL, "kind" text NOT NULL, "verantwortliche_user_id" uuid, "arbeitsmodus" text, "outline_steckbrief_url" text, "steckbrief_freigegeben" boolean DEFAULT false NOT NULL, "plane_project_url" text, "risikoliste_url" text, "dod_text" text, "start" date, "deadline" date, "status_cache" text, "trend_cache" text, "pflicht_minimum_state" jsonb DEFAULT '{}'::jsonb NOT NULL, "archiviert" boolean DEFAULT false NOT NULL, "archiviert_am" timestamp with time zone, "lessons_learned_url" text, "created_by" uuid, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL ); --> statement-breakpoint ALTER TABLE "milestone" ADD CONSTRAINT "milestone_project_id_project_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."project"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "project" ADD CONSTRAINT "project_area_id_area_id_fk" FOREIGN KEY ("area_id") REFERENCES "public"."area"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint ALTER TABLE "project" ADD CONSTRAINT "project_verantwortliche_user_id_user_id_fk" FOREIGN KEY ("verantwortliche_user_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "project" ADD CONSTRAINT "project_created_by_user_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint CREATE UNIQUE INDEX "uniq_area_slug" ON "area" USING btree ("slug");--> statement-breakpoint CREATE INDEX "idx_milestone_project" ON "milestone" USING btree ("project_id");--> statement-breakpoint CREATE INDEX "idx_project_area" ON "project" USING btree ("area_id");--> statement-breakpoint CREATE INDEX "idx_project_archived" ON "project" USING btree ("archiviert");