DO $$ BEGIN
  CREATE TYPE "public"."llm_provider_type" AS ENUM('google', 'openai-compat', 'mock');
EXCEPTION
  WHEN duplicate_object THEN NULL;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "llm_providers" (
  "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
  "slug" text NOT NULL,
  "name" text NOT NULL,
  "type" "public"."llm_provider_type" NOT NULL,
  "base_url" text,
  "api_key_enc" bytea,
  "is_active" boolean DEFAULT true NOT NULL,
  "created_at" timestamp with time zone DEFAULT now() NOT NULL,
  "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
  CONSTRAINT "llm_providers_slug_unique" UNIQUE("slug")
);
--> statement-breakpoint
CREATE TABLE "llm_model_cache" (
		"provider_id" uuid PRIMARY KEY NOT NULL,
		"models" jsonb NOT NULL,
	"fetched_at" timestamp with time zone DEFAULT now() NOT NULL,
	"error" text
);
--> statement-breakpoint
ALTER TABLE "llm_model_cache" ADD CONSTRAINT "llm_model_cache_provider_id_llm_providers_id_fk" FOREIGN KEY ("provider_id") REFERENCES "public"."llm_providers"("id") ON DELETE cascade ON UPDATE no action;
