CREATE TYPE "public"."support_comment_author_type" AS ENUM('user', 'admin', 'gitea');--> statement-breakpoint
CREATE TABLE "processed_gitea_events" (
	"id" text PRIMARY KEY NOT NULL,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "support_ticket_comments" (
	"id" text PRIMARY KEY NOT NULL,
	"ticket_id" text NOT NULL,
	"author_type" "support_comment_author_type" NOT NULL,
	"author_id" text,
	"body" text NOT NULL,
	"gitea_comment_id" integer,
	"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "support_tickets" ADD COLUMN "gitea_issue_number" integer;--> statement-breakpoint
ALTER TABLE "support_ticket_comments" ADD CONSTRAINT "support_ticket_comments_ticket_id_support_tickets_id_fk" FOREIGN KEY ("ticket_id") REFERENCES "public"."support_tickets"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "support_ticket_comments_ticket_idx" ON "support_ticket_comments" USING btree ("ticket_id","created_at");--> statement-breakpoint
CREATE INDEX "support_ticket_comments_gitea_comment_idx" ON "support_ticket_comments" USING btree ("gitea_comment_id");--> statement-breakpoint
CREATE INDEX "support_tickets_gitea_issue_idx" ON "support_tickets" USING btree ("gitea_issue_number");