CREATE TABLE "error_sources" ( "id" serial PRIMARY KEY NOT NULL, "project_id" integer NOT NULL, "kind" text NOT NULL, "bugsink_project_id" integer NOT NULL, "dsn" text NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "error_sources_bugsink_project_id_unique" UNIQUE("bugsink_project_id") ); --> statement-breakpoint CREATE TABLE "incident_settings" ( "project_id" integer PRIMARY KEY NOT NULL, "hook_secret" text NOT NULL, "policy" text DEFAULT 'backlog' NOT NULL, "triage_prompt" text, "environments" jsonb DEFAULT '["prod","production"]'::jsonb NOT NULL, "daily_limit" integer DEFAULT 5 NOT NULL, "ignore_pattern" text, "goal_id" integer, "webhook_auto" boolean DEFAULT false NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "incident_settings_hook_secret_unique" UNIQUE("hook_secret") ); --> statement-breakpoint CREATE TABLE "incidents" ( "id" serial PRIMARY KEY NOT NULL, "project_id" integer NOT NULL, "source" text NOT NULL, "bugsink_issue_id" text NOT NULL, "friendly_id" text, "title" text NOT NULL, "culprit" text, "level" text, "environment" text, "first_release" text, "last_release" text, "events" integer DEFAULT 1 NOT NULL, "first_seen" timestamp with time zone NOT NULL, "last_seen" timestamp with time zone NOT NULL, "url" text, "stack" text, "status" text DEFAULT 'new' NOT NULL, "decision" text, "decided_by" text, "decision_reason" text, "task_id" integer, "task_created_at" timestamp with time zone, "resolved_release" text, "resolved_at" timestamp with time zone, "regressions" integer DEFAULT 0 NOT NULL, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, CONSTRAINT "incidents_bugsink_issue_id_unique" UNIQUE("bugsink_issue_id") ); --> statement-breakpoint ALTER TABLE "error_sources" ADD CONSTRAINT "error_sources_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "incident_settings" ADD CONSTRAINT "incident_settings_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "incident_settings" ADD CONSTRAINT "incident_settings_goal_id_goals_id_fk" FOREIGN KEY ("goal_id") REFERENCES "public"."goals"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "incidents" ADD CONSTRAINT "incidents_project_id_projects_id_fk" FOREIGN KEY ("project_id") REFERENCES "public"."projects"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "incidents" ADD CONSTRAINT "incidents_task_id_tasks_id_fk" FOREIGN KEY ("task_id") REFERENCES "public"."tasks"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint CREATE UNIQUE INDEX "error_sources_project_kind" ON "error_sources" USING btree ("project_id","kind");