TypeScript 97.4%
SQL 1%
JavaScript 0.9%
CSS 0.6%
1CREATE TABLE "accounts" (2 "id" text PRIMARY KEY NOT NULL,3 "account_id" text NOT NULL,4 "provider_id" text NOT NULL,5 "user_id" text NOT NULL,6 "access_token" text,7 "refresh_token" text,8 "id_token" text,9 "access_token_expires_at" timestamp with time zone,10 "refresh_token_expires_at" timestamp with time zone,11 "scope" text,12 "password" text,13 "created_at" timestamp with time zone DEFAULT now() NOT NULL,14 "updated_at" timestamp with time zone DEFAULT now() NOT NULL15);16--> statement-breakpoint17CREATE TABLE "arena_responses" (18 "id" text PRIMARY KEY NOT NULL,19 "session_id" text NOT NULL,20 "model_key" text NOT NULL,21 "provider" text NOT NULL,22 "content" text DEFAULT '' NOT NULL,23 "reasoning" text,24 "status" text DEFAULT 'complete' NOT NULL,25 "error" jsonb,26 "usage" jsonb,27 "latency_ms" integer,28 "ttft_ms" integer,29 "cost_usd" double precision,30 "ratings" jsonb DEFAULT '{}'::jsonb NOT NULL,31 "created_at" timestamp with time zone DEFAULT now() NOT NULL32);33--> statement-breakpoint34CREATE TABLE "arena_sessions" (35 "id" text PRIMARY KEY NOT NULL,36 "user_id" text NOT NULL,37 "prompt" text NOT NULL,38 "system_prompt" text,39 "model_keys" jsonb NOT NULL,40 "settings" jsonb DEFAULT '{}'::jsonb NOT NULL,41 "created_at" timestamp with time zone DEFAULT now() NOT NULL42);43--> statement-breakpoint44CREATE TABLE "audit_events" (45 "id" text PRIMARY KEY NOT NULL,46 "user_id" text,47 "action" text NOT NULL,48 "ip_address" text,49 "user_agent" text,50 "meta" jsonb DEFAULT '{}'::jsonb NOT NULL,51 "created_at" timestamp with time zone DEFAULT now() NOT NULL52);53--> statement-breakpoint54CREATE TABLE "conversation_tags" (55 "conversation_id" text NOT NULL,56 "tag_id" text NOT NULL,57 CONSTRAINT "conversation_tags_conversation_id_tag_id_pk" PRIMARY KEY("conversation_id","tag_id")58);59--> statement-breakpoint60CREATE TABLE "conversations" (61 "id" text PRIMARY KEY NOT NULL,62 "user_id" text NOT NULL,63 "title" text DEFAULT 'New chat' NOT NULL,64 "title_source" text DEFAULT 'auto' NOT NULL,65 "folder_id" text,66 "pinned" boolean DEFAULT false NOT NULL,67 "archived" boolean DEFAULT false NOT NULL,68 "model_key" text,69 "provider" text,70 "system_prompt" text,71 "settings" jsonb DEFAULT '{}'::jsonb NOT NULL,72 "parent_conversation_id" text,73 "branched_from_message_id" text,74 "message_count" integer DEFAULT 0 NOT NULL,75 "total_cost_usd" double precision DEFAULT 0 NOT NULL,76 "total_input_tokens" integer DEFAULT 0 NOT NULL,77 "total_output_tokens" integer DEFAULT 0 NOT NULL,78 "last_message_at" timestamp with time zone,79 "created_at" timestamp with time zone DEFAULT now() NOT NULL,80 "updated_at" timestamp with time zone DEFAULT now() NOT NULL81);82--> statement-breakpoint83CREATE TABLE "folders" (84 "id" text PRIMARY KEY NOT NULL,85 "user_id" text NOT NULL,86 "name" text NOT NULL,87 "color" text,88 "sort_order" integer DEFAULT 0 NOT NULL,89 "created_at" timestamp with time zone DEFAULT now() NOT NULL90);91--> statement-breakpoint92CREATE TABLE "message_attachments" (93 "id" text PRIMARY KEY NOT NULL,94 "user_id" text NOT NULL,95 "message_id" text,96 "conversation_id" text,97 "kind" text NOT NULL,98 "name" text NOT NULL,99 "mime_type" text NOT NULL,100 "size_bytes" integer NOT NULL,101 "data_base64" text NOT NULL,102 "width" integer,103 "height" integer,104 "created_at" timestamp with time zone DEFAULT now() NOT NULL105);106--> statement-breakpoint107CREATE TABLE "messages" (108 "id" text PRIMARY KEY NOT NULL,109 "conversation_id" text NOT NULL,110 "user_id" text NOT NULL,111 "role" text NOT NULL,112 "content" text DEFAULT '' NOT NULL,113 "parts" jsonb DEFAULT '[]'::jsonb NOT NULL,114 "model_key" text,115 "provider" text,116 "status" text DEFAULT 'complete' NOT NULL,117 "finish_reason" text,118 "error" jsonb,119 "usage" jsonb,120 "settings" jsonb,121 "latency_ms" integer,122 "ttft_ms" integer,123 "cost_usd" double precision,124 "parent_message_id" text,125 "version" integer DEFAULT 1 NOT NULL,126 "active" boolean DEFAULT true NOT NULL,127 "created_at" timestamp with time zone DEFAULT now() NOT NULL,128 "updated_at" timestamp with time zone DEFAULT now() NOT NULL129);130--> statement-breakpoint131CREATE TABLE "model_presets" (132 "id" text PRIMARY KEY NOT NULL,133 "user_id" text NOT NULL,134 "name" text NOT NULL,135 "description" text,136 "icon" text,137 "model_key" text NOT NULL,138 "system_prompt" text,139 "parameters" jsonb DEFAULT '{}'::jsonb NOT NULL,140 "tools" jsonb DEFAULT '{}'::jsonb NOT NULL,141 "file_settings" jsonb DEFAULT '{}'::jsonb NOT NULL,142 "sort_order" integer DEFAULT 0 NOT NULL,143 "created_at" timestamp with time zone DEFAULT now() NOT NULL,144 "updated_at" timestamp with time zone DEFAULT now() NOT NULL145);146--> statement-breakpoint147CREATE TABLE "model_sync_runs" (148 "id" text PRIMARY KEY NOT NULL,149 "provider" text NOT NULL,150 "triggered_by" text DEFAULT 'schedule' NOT NULL,151 "started_at" timestamp with time zone DEFAULT now() NOT NULL,152 "finished_at" timestamp with time zone,153 "ok" boolean,154 "models_found" integer,155 "models_added" integer,156 "models_removed" integer,157 "latency_ms" integer,158 "error_code" text,159 "error_message" text160);161--> statement-breakpoint162CREATE TABLE "models" (163 "key" text PRIMARY KEY NOT NULL,164 "provider" text NOT NULL,165 "model_id" text NOT NULL,166 "display_name" text NOT NULL,167 "family" text,168 "capabilities" jsonb NOT NULL,169 "limits" jsonb DEFAULT '{}'::jsonb NOT NULL,170 "parameters" jsonb DEFAULT '{}'::jsonb NOT NULL,171 "pricing" jsonb,172 "status" text DEFAULT 'unknown' NOT NULL,173 "source" text DEFAULT 'catalog' NOT NULL,174 "hidden" boolean DEFAULT false NOT NULL,175 "sort_weight" integer DEFAULT 0 NOT NULL,176 "metadata" jsonb DEFAULT '{}'::jsonb NOT NULL,177 "first_seen_at" timestamp with time zone DEFAULT now() NOT NULL,178 "last_seen_at" timestamp with time zone DEFAULT now() NOT NULL,179 "updated_at" timestamp with time zone DEFAULT now() NOT NULL180);181--> statement-breakpoint182CREATE TABLE "prompt_presets" (183 "id" text PRIMARY KEY NOT NULL,184 "user_id" text NOT NULL,185 "name" text NOT NULL,186 "description" text,187 "icon" text,188 "system_prompt" text NOT NULL,189 "default_model_key" text,190 "parameters" jsonb DEFAULT '{}'::jsonb NOT NULL,191 "tools" jsonb DEFAULT '{}'::jsonb NOT NULL,192 "sort_order" integer DEFAULT 0 NOT NULL,193 "created_at" timestamp with time zone DEFAULT now() NOT NULL,194 "updated_at" timestamp with time zone DEFAULT now() NOT NULL195);196--> statement-breakpoint197CREATE TABLE "provider_connections" (198 "id" text PRIMARY KEY NOT NULL,199 "user_id" text NOT NULL,200 "provider" text NOT NULL,201 "encrypted_key" text NOT NULL,202 "key_hint" text NOT NULL,203 "key_fingerprint" text NOT NULL,204 "status" text DEFAULT 'unverified' NOT NULL,205 "last_validated_at" timestamp with time zone,206 "last_validation_error" text,207 "last_success_at" timestamp with time zone,208 "last_error_at" timestamp with time zone,209 "last_error_code" text,210 "models_available" integer,211 "created_at" timestamp with time zone DEFAULT now() NOT NULL,212 "updated_at" timestamp with time zone DEFAULT now() NOT NULL213);214--> statement-breakpoint215CREATE TABLE "sessions" (216 "id" text PRIMARY KEY NOT NULL,217 "expires_at" timestamp with time zone NOT NULL,218 "token" text NOT NULL,219 "created_at" timestamp with time zone DEFAULT now() NOT NULL,220 "updated_at" timestamp with time zone DEFAULT now() NOT NULL,221 "ip_address" text,222 "user_agent" text,223 "user_id" text NOT NULL224);225--> statement-breakpoint226CREATE TABLE "shared_conversations" (227 "id" text PRIMARY KEY NOT NULL,228 "conversation_id" text NOT NULL,229 "user_id" text NOT NULL,230 "title" text NOT NULL,231 "snapshot" jsonb NOT NULL,232 "is_public" boolean DEFAULT true NOT NULL,233 "view_count" integer DEFAULT 0 NOT NULL,234 "created_at" timestamp with time zone DEFAULT now() NOT NULL,235 "revoked_at" timestamp with time zone236);237--> statement-breakpoint238CREATE TABLE "tags" (239 "id" text PRIMARY KEY NOT NULL,240 "user_id" text NOT NULL,241 "name" text NOT NULL,242 "color" text,243 "created_at" timestamp with time zone DEFAULT now() NOT NULL244);245--> statement-breakpoint246CREATE TABLE "usage_records" (247 "id" text PRIMARY KEY NOT NULL,248 "user_id" text NOT NULL,249 "conversation_id" text,250 "message_id" text,251 "arena_session_id" text,252 "provider" text NOT NULL,253 "model_key" text NOT NULL,254 "kind" text DEFAULT 'chat' NOT NULL,255 "status" text DEFAULT 'ok' NOT NULL,256 "error_code" text,257 "input_tokens" integer DEFAULT 0 NOT NULL,258 "output_tokens" integer DEFAULT 0 NOT NULL,259 "cached_tokens" integer DEFAULT 0 NOT NULL,260 "reasoning_tokens" integer DEFAULT 0 NOT NULL,261 "cost_usd" double precision,262 "latency_ms" integer,263 "ttft_ms" integer,264 "created_at" timestamp with time zone DEFAULT now() NOT NULL265);266--> statement-breakpoint267CREATE TABLE "user_model_favorites" (268 "user_id" text NOT NULL,269 "model_key" text NOT NULL,270 "created_at" timestamp with time zone DEFAULT now() NOT NULL,271 CONSTRAINT "user_model_favorites_user_id_model_key_pk" PRIMARY KEY("user_id","model_key")272);273--> statement-breakpoint274CREATE TABLE "user_model_recents" (275 "user_id" text NOT NULL,276 "model_key" text NOT NULL,277 "used_at" timestamp with time zone DEFAULT now() NOT NULL,278 "uses" integer DEFAULT 1 NOT NULL,279 CONSTRAINT "user_model_recents_user_id_model_key_pk" PRIMARY KEY("user_id","model_key")280);281--> statement-breakpoint282CREATE TABLE "user_preferences" (283 "user_id" text PRIMARY KEY NOT NULL,284 "theme" text DEFAULT 'system' NOT NULL,285 "language" text DEFAULT 'en' NOT NULL,286 "default_model_key" text,287 "default_system_prompt" text,288 "enter_to_send" boolean DEFAULT true NOT NULL,289 "streaming" boolean DEFAULT true NOT NULL,290 "code_wrap" boolean DEFAULT false NOT NULL,291 "show_reasoning" boolean DEFAULT true NOT NULL,292 "show_costs" boolean DEFAULT true NOT NULL,293 "auto_title" boolean DEFAULT true NOT NULL,294 "extra" jsonb DEFAULT '{}'::jsonb NOT NULL,295 "updated_at" timestamp with time zone DEFAULT now() NOT NULL296);297--> statement-breakpoint298CREATE TABLE "users" (299 "id" text PRIMARY KEY NOT NULL,300 "name" text DEFAULT '' NOT NULL,301 "email" text NOT NULL,302 "email_verified" boolean DEFAULT false NOT NULL,303 "image" text,304 "role" text DEFAULT 'user' NOT NULL,305 "onboarding_completed_at" timestamp with time zone,306 "created_at" timestamp with time zone DEFAULT now() NOT NULL,307 "updated_at" timestamp with time zone DEFAULT now() NOT NULL308);309--> statement-breakpoint310CREATE TABLE "verifications" (311 "id" text PRIMARY KEY NOT NULL,312 "identifier" text NOT NULL,313 "value" text NOT NULL,314 "expires_at" timestamp with time zone NOT NULL,315 "created_at" timestamp with time zone DEFAULT now() NOT NULL,316 "updated_at" timestamp with time zone DEFAULT now() NOT NULL317);318--> statement-breakpoint319ALTER TABLE "accounts" ADD CONSTRAINT "accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint320ALTER TABLE "arena_responses" ADD CONSTRAINT "arena_responses_session_id_arena_sessions_id_fk" FOREIGN KEY ("session_id") REFERENCES "public"."arena_sessions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint321ALTER TABLE "arena_sessions" ADD CONSTRAINT "arena_sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint322ALTER TABLE "audit_events" ADD CONSTRAINT "audit_events_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint323ALTER TABLE "conversation_tags" ADD CONSTRAINT "conversation_tags_conversation_id_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."conversations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint324ALTER TABLE "conversation_tags" ADD CONSTRAINT "conversation_tags_tag_id_tags_id_fk" FOREIGN KEY ("tag_id") REFERENCES "public"."tags"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint325ALTER TABLE "conversations" ADD CONSTRAINT "conversations_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint326ALTER TABLE "conversations" ADD CONSTRAINT "conversations_folder_id_folders_id_fk" FOREIGN KEY ("folder_id") REFERENCES "public"."folders"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint327ALTER TABLE "folders" ADD CONSTRAINT "folders_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint328ALTER TABLE "message_attachments" ADD CONSTRAINT "message_attachments_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint329ALTER TABLE "message_attachments" ADD CONSTRAINT "message_attachments_message_id_messages_id_fk" FOREIGN KEY ("message_id") REFERENCES "public"."messages"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint330ALTER TABLE "message_attachments" ADD CONSTRAINT "message_attachments_conversation_id_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."conversations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint331ALTER TABLE "messages" ADD CONSTRAINT "messages_conversation_id_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."conversations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint332ALTER TABLE "messages" ADD CONSTRAINT "messages_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint333ALTER TABLE "model_presets" ADD CONSTRAINT "model_presets_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint334ALTER TABLE "prompt_presets" ADD CONSTRAINT "prompt_presets_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint335ALTER TABLE "provider_connections" ADD CONSTRAINT "provider_connections_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint336ALTER TABLE "sessions" ADD CONSTRAINT "sessions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint337ALTER TABLE "shared_conversations" ADD CONSTRAINT "shared_conversations_conversation_id_conversations_id_fk" FOREIGN KEY ("conversation_id") REFERENCES "public"."conversations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint338ALTER TABLE "shared_conversations" ADD CONSTRAINT "shared_conversations_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint339ALTER TABLE "tags" ADD CONSTRAINT "tags_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint340ALTER TABLE "usage_records" ADD CONSTRAINT "usage_records_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint341ALTER TABLE "user_model_favorites" ADD CONSTRAINT "user_model_favorites_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint342ALTER TABLE "user_model_recents" ADD CONSTRAINT "user_model_recents_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint343ALTER TABLE "user_preferences" ADD CONSTRAINT "user_preferences_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint344CREATE INDEX "accounts_user_idx" ON "accounts" USING btree ("user_id");--> statement-breakpoint345CREATE INDEX "arena_responses_session_idx" ON "arena_responses" USING btree ("session_id");--> statement-breakpoint346CREATE INDEX "arena_sessions_user_idx" ON "arena_sessions" USING btree ("user_id","created_at");--> statement-breakpoint347CREATE INDEX "audit_user_created_idx" ON "audit_events" USING btree ("user_id","created_at");--> statement-breakpoint348CREATE INDEX "conversations_user_updated_idx" ON "conversations" USING btree ("user_id","updated_at");--> statement-breakpoint349CREATE INDEX "conversations_user_folder_idx" ON "conversations" USING btree ("user_id","folder_id");--> statement-breakpoint350CREATE INDEX "conversations_user_model_idx" ON "conversations" USING btree ("user_id","model_key");--> statement-breakpoint351CREATE INDEX "folders_user_idx" ON "folders" USING btree ("user_id");--> statement-breakpoint352CREATE INDEX "attachments_message_idx" ON "message_attachments" USING btree ("message_id");--> statement-breakpoint353CREATE INDEX "attachments_user_idx" ON "message_attachments" USING btree ("user_id");--> statement-breakpoint354CREATE INDEX "messages_conversation_created_idx" ON "messages" USING btree ("conversation_id","created_at");--> statement-breakpoint355CREATE INDEX "messages_user_idx" ON "messages" USING btree ("user_id");--> statement-breakpoint356CREATE INDEX "model_presets_user_idx" ON "model_presets" USING btree ("user_id");--> statement-breakpoint357CREATE INDEX "model_sync_runs_provider_started_idx" ON "model_sync_runs" USING btree ("provider","started_at");--> statement-breakpoint358CREATE INDEX "models_provider_idx" ON "models" USING btree ("provider");--> statement-breakpoint359CREATE INDEX "models_status_idx" ON "models" USING btree ("status");--> statement-breakpoint360CREATE INDEX "prompt_presets_user_idx" ON "prompt_presets" USING btree ("user_id");--> statement-breakpoint361CREATE UNIQUE INDEX "provider_connections_user_provider_uq" ON "provider_connections" USING btree ("user_id","provider");--> statement-breakpoint362CREATE UNIQUE INDEX "sessions_token_uq" ON "sessions" USING btree ("token");--> statement-breakpoint363CREATE INDEX "sessions_user_idx" ON "sessions" USING btree ("user_id");--> statement-breakpoint364CREATE INDEX "shared_conversation_idx" ON "shared_conversations" USING btree ("conversation_id");--> statement-breakpoint365CREATE UNIQUE INDEX "tags_user_name_uq" ON "tags" USING btree ("user_id","name");--> statement-breakpoint366CREATE INDEX "usage_user_created_idx" ON "usage_records" USING btree ("user_id","created_at");--> statement-breakpoint367CREATE INDEX "usage_user_provider_idx" ON "usage_records" USING btree ("user_id","provider");--> statement-breakpoint368CREATE INDEX "usage_user_model_idx" ON "usage_records" USING btree ("user_id","model_key");--> statement-breakpoint369CREATE UNIQUE INDEX "users_email_uq" ON "users" USING btree ("email");--> statement-breakpoint370CREATE INDEX "verifications_identifier_idx" ON "verifications" USING btree ("identifier");