-- Public API anahtarları — better-auth `apiKey` plugin'inin tablosu (model -- "apikey", usePlural → "apikeys"). Kolon seti plugin şemasının birebir -- karşılığı; "key" kolonu secret'ın SHA256 hash'i (düz metin sadece üretim -- anında bir kez gösterilir). "metadata" JSON string (dailyDecodeLimit gibi -- anahtar-bazlı limitler burada taşınır). CREATE TABLE IF NOT EXISTS "apikeys" ( "id" text PRIMARY KEY NOT NULL, "name" text, "start" text, "prefix" text, "key" text NOT NULL, "user_id" uuid NOT NULL, "refill_interval" integer, "refill_amount" integer, "last_refill_at" timestamp with time zone, "enabled" boolean DEFAULT true NOT NULL, "rate_limit_enabled" boolean DEFAULT true NOT NULL, "rate_limit_time_window" integer, "rate_limit_max" integer, "request_count" integer DEFAULT 0 NOT NULL, "remaining" integer, "last_request" timestamp with time zone, "expires_at" timestamp with time zone, "created_at" timestamp with time zone DEFAULT now() NOT NULL, "updated_at" timestamp with time zone DEFAULT now() NOT NULL, "permissions" text, "metadata" text ); --> statement-breakpoint DO $$ BEGIN ALTER TABLE "apikeys" ADD CONSTRAINT "apikeys_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; EXCEPTION WHEN duplicate_object THEN null; END $$; --> statement-breakpoint CREATE INDEX IF NOT EXISTS "apikeys_key_idx" ON "apikeys" ("key"); --> statement-breakpoint CREATE INDEX IF NOT EXISTS "apikeys_user_id_idx" ON "apikeys" ("user_id");