Browse Source

refactor: consolidate migrations, extract shared utilities, fix bugbot issues

Merge 6 index migrations (0068-0073) into single idempotent migration.
Extract reusable utilities from duplicated code across the codebase:

- TTLMap<K,V>: generic LRU+TTL cache replacing 3 inline implementations
- createAbortError: shared abort error factory from 2 components
- startLeaderLockKeepAlive: shared leader lock renewal from 2 schedulers
- ProbeLogsBatcher: data-fetching infra extracted from sparkline component
- buildUsageLogConditions: shared SQL filter builder from 3 query functions

Additional cleanup:
- Simplify useInViewOnce hook (remove unused options, keep shared observer pool)
- Remove dead code (sumKeyTotalCostById, unexport internal types)
- Hardcode env var defaults (ENDPOINT_CIRCUIT_HEALTH_CACHE_MAX_SIZE,
  ENDPOINT_PROBE_IDLE_DB_POLL_INTERVAL_MS)
- Fix in-flight dedup race condition in getProviderStatistics
- Fix yesterday/today interval boundary inconsistency (lte -> lt)
- Add NaN guard for limitPerEndpoint in batch probe logs
- Add updatedAt to deleteProvider for audit consistency
- Log swallowed flush() errors in batchers instead of silently catching
ding113 1 week ago
parent
commit
c2c6757eba
35 changed files with 1042 additions and 17079 deletions
  1. 14 0
      drizzle/0068_flaky_swarm.sql
  2. 0 2
      drizzle/0068_fuzzy_quasar.sql
  3. 0 6
      drizzle/0069_broad_hellfire_club.sql
  4. 0 5
      drizzle/0070_warm_lilandra.sql
  5. 0 1
      drizzle/0071_motionless_wind_dancer.sql
  6. 0 5
      drizzle/0072_absurd_gwen_stacy.sql
  7. 0 1
      drizzle/0073_minor_franklin_richards.sql
  8. 190 11
      drizzle/meta/0068_snapshot.json
  9. 0 3118
      drizzle/meta/0069_snapshot.json
  10. 0 3156
      drizzle/meta/0070_snapshot.json
  11. 0 3171
      drizzle/meta/0071_snapshot.json
  12. 0 3215
      drizzle/meta/0072_snapshot.json
  13. 0 3237
      drizzle/meta/0073_snapshot.json
  14. 2 37
      drizzle/meta/_journal.json
  15. 21 418
      src/app/[locale]/settings/providers/_components/endpoint-latency-sparkline.tsx
  16. 6 12
      src/app/[locale]/settings/providers/_components/provider-endpoint-hover.tsx
  17. 10 0
      src/lib/abort-utils.ts
  18. 79 0
      src/lib/cache/ttl-map.ts
  19. 1 16
      src/lib/endpoint-circuit-breaker.ts
  20. 27 116
      src/lib/hooks/use-in-view-once.ts
  21. 55 0
      src/lib/provider-endpoints/leader-lock.ts
  22. 12 53
      src/lib/provider-endpoints/probe-log-cleanup.ts
  23. 387 0
      src/lib/provider-endpoints/probe-logs-batcher.ts
  24. 15 62
      src/lib/provider-endpoints/probe-scheduler.ts
  25. 57 0
      src/repository/_shared/usage-log-filters.ts
  26. 2 2
      src/repository/overview.ts
  27. 2 1
      src/repository/provider-endpoints-batch.ts
  28. 3 2
      src/repository/provider.ts
  29. 9 62
      src/repository/statistics.ts
  30. 39 321
      src/repository/usage-logs.ts
  31. 0 1
      tests/unit/actions/my-usage-concurrent-inherit.test.ts
  32. 2 5
      tests/unit/actions/my-usage-consistency.test.ts
  33. 0 43
      tests/unit/lib/endpoint-circuit-breaker.test.ts
  34. 1 0
      tests/unit/lib/provider-endpoints/probe-scheduler.test.ts
  35. 108 0
      tests/unit/lib/ttl-map.test.ts

+ 14 - 0
drizzle/0068_flaky_swarm.sql

@@ -0,0 +1,14 @@
+-- Note: message_request is a high-write table. Standard CREATE INDEX may block writes during index creation.
+-- Drizzle migrator does not support CREATE INDEX CONCURRENTLY. If write blocking is a concern,
+-- manually pre-create indexes with CONCURRENTLY before running this migration (IF NOT EXISTS prevents conflicts).
+CREATE INDEX IF NOT EXISTS "idx_keys_key" ON "keys" USING btree ("key");--> statement-breakpoint
+CREATE INDEX IF NOT EXISTS "idx_message_request_key_created_at_id" ON "message_request" USING btree ("key","created_at" DESC NULLS LAST,"id" DESC NULLS LAST) WHERE "message_request"."deleted_at" IS NULL;--> statement-breakpoint
+CREATE INDEX IF NOT EXISTS "idx_message_request_key_model_active" ON "message_request" USING btree ("key","model") WHERE "message_request"."deleted_at" IS NULL AND "message_request"."model" IS NOT NULL AND ("message_request"."blocked_by" IS NULL OR "message_request"."blocked_by" <> 'warmup');--> statement-breakpoint
+CREATE INDEX IF NOT EXISTS "idx_message_request_key_endpoint_active" ON "message_request" USING btree ("key","endpoint") WHERE "message_request"."deleted_at" IS NULL AND "message_request"."endpoint" IS NOT NULL AND ("message_request"."blocked_by" IS NULL OR "message_request"."blocked_by" <> 'warmup');--> statement-breakpoint
+CREATE INDEX IF NOT EXISTS "idx_message_request_created_at_id_active" ON "message_request" USING btree ("created_at" DESC NULLS LAST,"id" DESC NULLS LAST) WHERE "message_request"."deleted_at" IS NULL;--> statement-breakpoint
+CREATE INDEX IF NOT EXISTS "idx_message_request_model_active" ON "message_request" USING btree ("model") WHERE "message_request"."deleted_at" IS NULL AND "message_request"."model" IS NOT NULL;--> statement-breakpoint
+CREATE INDEX IF NOT EXISTS "idx_message_request_status_code_active" ON "message_request" USING btree ("status_code") WHERE "message_request"."deleted_at" IS NULL AND "message_request"."status_code" IS NOT NULL;--> statement-breakpoint
+CREATE INDEX IF NOT EXISTS "idx_provider_endpoints_pick_enabled" ON "provider_endpoints" USING btree ("vendor_id","provider_type","is_enabled","sort_order","id") WHERE "provider_endpoints"."deleted_at" IS NULL;--> statement-breakpoint
+CREATE INDEX IF NOT EXISTS "idx_providers_vendor_type_url_active" ON "providers" USING btree ("provider_vendor_id","provider_type","url") WHERE "providers"."deleted_at" IS NULL;--> statement-breakpoint
+CREATE INDEX IF NOT EXISTS "idx_providers_enabled_vendor_type" ON "providers" USING btree ("provider_vendor_id","provider_type") WHERE "providers"."deleted_at" IS NULL AND "providers"."is_enabled" = true AND "providers"."provider_vendor_id" IS NOT NULL AND "providers"."provider_vendor_id" > 0;--> statement-breakpoint
+CREATE INDEX IF NOT EXISTS "idx_users_tags_gin" ON "users" USING gin ("tags") WHERE "users"."deleted_at" IS NULL;

+ 0 - 2
drizzle/0068_fuzzy_quasar.sql

@@ -1,2 +0,0 @@
-CREATE INDEX IF NOT EXISTS "idx_provider_endpoints_pick_enabled" ON "provider_endpoints" USING btree ("vendor_id","provider_type","is_enabled","sort_order","id") WHERE "provider_endpoints"."deleted_at" IS NULL;--> statement-breakpoint
-CREATE INDEX IF NOT EXISTS "idx_providers_vendor_type_url_active" ON "providers" USING btree ("provider_vendor_id","provider_type","url") WHERE "providers"."deleted_at" IS NULL;

+ 0 - 6
drizzle/0069_broad_hellfire_club.sql

@@ -1,6 +0,0 @@
--- 注意:message_request 为高写入表,标准 CREATE INDEX 可能在建索引期间阻塞写入。
--- Drizzle migrator 不支持 CREATE INDEX CONCURRENTLY;如对停写敏感,可在维护窗口升级,
--- 或在升级前手动用 CONCURRENTLY 预创建同名索引(本迁移已使用 IF NOT EXISTS,预建不会冲突)。
-CREATE INDEX IF NOT EXISTS "idx_message_request_key_created_at_id" ON "message_request" USING btree ("key","created_at" DESC NULLS LAST,"id" DESC NULLS LAST) WHERE "message_request"."deleted_at" IS NULL;--> statement-breakpoint
-CREATE INDEX IF NOT EXISTS "idx_message_request_model_active" ON "message_request" USING btree ("model") WHERE "message_request"."deleted_at" IS NULL AND "message_request"."model" IS NOT NULL;--> statement-breakpoint
-CREATE INDEX IF NOT EXISTS "idx_message_request_status_code_active" ON "message_request" USING btree ("status_code") WHERE "message_request"."deleted_at" IS NULL AND "message_request"."status_code" IS NOT NULL;

+ 0 - 5
drizzle/0070_warm_lilandra.sql

@@ -1,5 +0,0 @@
--- 注意:message_request 为高写入表,标准 CREATE INDEX 可能在建索引期间阻塞写入。
--- Drizzle migrator 不支持 CREATE INDEX CONCURRENTLY;如对停写敏感,可在维护窗口升级,
--- 或在升级前手动用 CONCURRENTLY 预创建同名索引(本迁移已使用 IF NOT EXISTS,预建不会冲突)。
-CREATE INDEX IF NOT EXISTS "idx_message_request_created_at_id_active" ON "message_request" USING btree ("created_at" DESC NULLS LAST,"id" DESC NULLS LAST) WHERE "message_request"."deleted_at" IS NULL;--> statement-breakpoint
-CREATE INDEX IF NOT EXISTS "idx_users_tags_gin" ON "users" USING gin ("tags") WHERE "users"."deleted_at" IS NULL;

+ 0 - 1
drizzle/0071_motionless_wind_dancer.sql

@@ -1 +0,0 @@
-CREATE INDEX IF NOT EXISTS "idx_keys_key" ON "keys" USING btree ("key");

+ 0 - 5
drizzle/0072_absurd_gwen_stacy.sql

@@ -1,5 +0,0 @@
--- 注意:message_request 为高写入表,标准 CREATE INDEX 可能在建索引期间阻塞写入。
--- Drizzle migrator 不支持 CREATE INDEX CONCURRENTLY;如对停写敏感,可在维护窗口升级,
--- 或在升级前手动用 CONCURRENTLY 预创建同名索引(本迁移已使用 IF NOT EXISTS,预建不会冲突)。
-CREATE INDEX IF NOT EXISTS "idx_message_request_key_model_active" ON "message_request" USING btree ("key","model") WHERE "message_request"."deleted_at" IS NULL AND "message_request"."model" IS NOT NULL AND ("message_request"."blocked_by" IS NULL OR "message_request"."blocked_by" <> 'warmup');--> statement-breakpoint
-CREATE INDEX IF NOT EXISTS "idx_message_request_key_endpoint_active" ON "message_request" USING btree ("key","endpoint") WHERE "message_request"."deleted_at" IS NULL AND "message_request"."endpoint" IS NOT NULL AND ("message_request"."blocked_by" IS NULL OR "message_request"."blocked_by" <> 'warmup');

+ 0 - 1
drizzle/0073_minor_franklin_richards.sql

@@ -1 +0,0 @@
-CREATE INDEX IF NOT EXISTS "idx_providers_enabled_vendor_type" ON "providers" USING btree ("provider_vendor_id","provider_type") WHERE "providers"."deleted_at" IS NULL AND "providers"."is_enabled" = true AND "providers"."provider_vendor_id" IS NOT NULL AND "providers"."provider_vendor_id" > 0;

+ 190 - 11
drizzle/meta/0068_snapshot.json

@@ -1,5 +1,5 @@
 {
-  "id": "e6503137-9fe6-450f-9918-f2c5a7315001",
+  "id": "81847b3d-5ce4-4fb0-bad1-9e4570f3c5fb",
   "prevId": "c4820501-71eb-4492-b9cb-dd19c5def277",
   "version": "7",
   "dialect": "postgresql",
@@ -312,6 +312,21 @@
           "method": "btree",
           "with": {}
         },
+        "idx_keys_key": {
+          "name": "idx_keys_key",
+          "columns": [
+            {
+              "expression": "key",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            }
+          ],
+          "isUnique": false,
+          "concurrently": false,
+          "method": "btree",
+          "with": {}
+        },
         "idx_keys_created_at": {
           "name": "idx_keys_created_at",
           "columns": [
@@ -752,6 +767,132 @@
           "method": "btree",
           "with": {}
         },
+        "idx_message_request_key_created_at_id": {
+          "name": "idx_message_request_key_created_at_id",
+          "columns": [
+            {
+              "expression": "key",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            },
+            {
+              "expression": "created_at",
+              "isExpression": false,
+              "asc": false,
+              "nulls": "last"
+            },
+            {
+              "expression": "id",
+              "isExpression": false,
+              "asc": false,
+              "nulls": "last"
+            }
+          ],
+          "isUnique": false,
+          "where": "\"message_request\".\"deleted_at\" IS NULL",
+          "concurrently": false,
+          "method": "btree",
+          "with": {}
+        },
+        "idx_message_request_key_model_active": {
+          "name": "idx_message_request_key_model_active",
+          "columns": [
+            {
+              "expression": "key",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            },
+            {
+              "expression": "model",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            }
+          ],
+          "isUnique": false,
+          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"model\" IS NOT NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
+          "concurrently": false,
+          "method": "btree",
+          "with": {}
+        },
+        "idx_message_request_key_endpoint_active": {
+          "name": "idx_message_request_key_endpoint_active",
+          "columns": [
+            {
+              "expression": "key",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            },
+            {
+              "expression": "endpoint",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            }
+          ],
+          "isUnique": false,
+          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"endpoint\" IS NOT NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
+          "concurrently": false,
+          "method": "btree",
+          "with": {}
+        },
+        "idx_message_request_created_at_id_active": {
+          "name": "idx_message_request_created_at_id_active",
+          "columns": [
+            {
+              "expression": "created_at",
+              "isExpression": false,
+              "asc": false,
+              "nulls": "last"
+            },
+            {
+              "expression": "id",
+              "isExpression": false,
+              "asc": false,
+              "nulls": "last"
+            }
+          ],
+          "isUnique": false,
+          "where": "\"message_request\".\"deleted_at\" IS NULL",
+          "concurrently": false,
+          "method": "btree",
+          "with": {}
+        },
+        "idx_message_request_model_active": {
+          "name": "idx_message_request_model_active",
+          "columns": [
+            {
+              "expression": "model",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            }
+          ],
+          "isUnique": false,
+          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"model\" IS NOT NULL",
+          "concurrently": false,
+          "method": "btree",
+          "with": {}
+        },
+        "idx_message_request_status_code_active": {
+          "name": "idx_message_request_status_code_active",
+          "columns": [
+            {
+              "expression": "status_code",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            }
+          ],
+          "isUnique": false,
+          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"status_code\" IS NOT NULL",
+          "concurrently": false,
+          "method": "btree",
+          "with": {}
+        },
         "idx_message_request_created_at": {
           "name": "idx_message_request_created_at",
           "columns": [
@@ -2071,6 +2212,34 @@
           "method": "btree",
           "with": {}
         },
+        "idx_providers_vendor_type_url_active": {
+          "name": "idx_providers_vendor_type_url_active",
+          "columns": [
+            {
+              "expression": "provider_vendor_id",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            },
+            {
+              "expression": "provider_type",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            },
+            {
+              "expression": "url",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            }
+          ],
+          "isUnique": false,
+          "where": "\"providers\".\"deleted_at\" IS NULL",
+          "concurrently": false,
+          "method": "btree",
+          "with": {}
+        },
         "idx_providers_created_at": {
           "name": "idx_providers_created_at",
           "columns": [
@@ -2123,8 +2292,8 @@
           "method": "btree",
           "with": {}
         },
-        "idx_providers_vendor_type_url_active": {
-          "name": "idx_providers_vendor_type_url_active",
+        "idx_providers_enabled_vendor_type": {
+          "name": "idx_providers_enabled_vendor_type",
           "columns": [
             {
               "expression": "provider_vendor_id",
@@ -2137,16 +2306,10 @@
               "isExpression": false,
               "asc": true,
               "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
             }
           ],
           "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
+          "where": "\"providers\".\"deleted_at\" IS NULL AND \"providers\".\"is_enabled\" = true AND \"providers\".\"provider_vendor_id\" IS NOT NULL AND \"providers\".\"provider_vendor_id\" > 0",
           "concurrently": false,
           "method": "btree",
           "with": {}
@@ -2862,6 +3025,22 @@
           "method": "btree",
           "with": {}
         },
+        "idx_users_tags_gin": {
+          "name": "idx_users_tags_gin",
+          "columns": [
+            {
+              "expression": "tags",
+              "isExpression": false,
+              "asc": true,
+              "nulls": "last"
+            }
+          ],
+          "isUnique": false,
+          "where": "\"users\".\"deleted_at\" IS NULL",
+          "concurrently": false,
+          "method": "gin",
+          "with": {}
+        },
         "idx_users_created_at": {
           "name": "idx_users_created_at",
           "columns": [
@@ -3055,4 +3234,4 @@
     "schemas": {},
     "tables": {}
   }
-}
+}

+ 0 - 3118
drizzle/meta/0069_snapshot.json

@@ -1,3118 +0,0 @@
-{
-  "id": "30ac31f0-6588-443f-a197-1c16dab31e1c",
-  "prevId": "e6503137-9fe6-450f-9918-f2c5a7315001",
-  "version": "7",
-  "dialect": "postgresql",
-  "tables": {
-    "public.error_rules": {
-      "name": "error_rules",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "pattern": {
-          "name": "pattern",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'regex'"
-        },
-        "category": {
-          "name": "category",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "override_response": {
-          "name": "override_response",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "override_status_code": {
-          "name": "override_status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "is_default": {
-          "name": "is_default",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_error_rules_enabled": {
-          "name": "idx_error_rules_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "unique_pattern": {
-          "name": "unique_pattern",
-          "columns": [
-            {
-              "expression": "pattern",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_category": {
-          "name": "idx_category",
-          "columns": [
-            {
-              "expression": "category",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_match_type": {
-          "name": "idx_match_type",
-          "columns": [
-            {
-              "expression": "match_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.keys": {
-      "name": "keys",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "user_id": {
-          "name": "user_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": true
-        },
-        "expires_at": {
-          "name": "expires_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "can_login_web_ui": {
-          "name": "can_login_web_ui",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_daily_usd": {
-          "name": "limit_daily_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "provider_group": {
-          "name": "provider_group",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'default'"
-        },
-        "cache_ttl_preference": {
-          "name": "cache_ttl_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_keys_user_id": {
-          "name": "idx_keys_user_id",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_created_at": {
-          "name": "idx_keys_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_deleted_at": {
-          "name": "idx_keys_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.message_request": {
-      "name": "message_request",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "provider_id": {
-          "name": "provider_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "user_id": {
-          "name": "user_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "model": {
-          "name": "model",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "duration_ms": {
-          "name": "duration_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cost_usd": {
-          "name": "cost_usd",
-          "type": "numeric(21, 15)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0'"
-        },
-        "cost_multiplier": {
-          "name": "cost_multiplier",
-          "type": "numeric(10, 4)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "session_id": {
-          "name": "session_id",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "request_sequence": {
-          "name": "request_sequence",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 1
-        },
-        "provider_chain": {
-          "name": "provider_chain",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "status_code": {
-          "name": "status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "api_type": {
-          "name": "api_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "endpoint": {
-          "name": "endpoint",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "original_model": {
-          "name": "original_model",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "input_tokens": {
-          "name": "input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "output_tokens": {
-          "name": "output_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "ttfb_ms": {
-          "name": "ttfb_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_input_tokens": {
-          "name": "cache_creation_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_read_input_tokens": {
-          "name": "cache_read_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_5m_input_tokens": {
-          "name": "cache_creation_5m_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_1h_input_tokens": {
-          "name": "cache_creation_1h_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_ttl_applied": {
-          "name": "cache_ttl_applied",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "context_1m_applied": {
-          "name": "context_1m_applied",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "special_settings": {
-          "name": "special_settings",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_message": {
-          "name": "error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_stack": {
-          "name": "error_stack",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_cause": {
-          "name": "error_cause",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "blocked_by": {
-          "name": "blocked_by",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "blocked_reason": {
-          "name": "blocked_reason",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "user_agent": {
-          "name": "user_agent",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "messages_count": {
-          "name": "messages_count",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_message_request_user_date_cost": {
-          "name": "idx_message_request_user_date_cost",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "cost_usd",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_user_query": {
-          "name": "idx_message_request_user_query",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_id": {
-          "name": "idx_message_request_session_id",
-          "columns": [
-            {
-              "expression": "session_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_id_prefix": {
-          "name": "idx_message_request_session_id_prefix",
-          "columns": [
-            {
-              "expression": "\"session_id\" varchar_pattern_ops",
-              "asc": true,
-              "isExpression": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_seq": {
-          "name": "idx_message_request_session_seq",
-          "columns": [
-            {
-              "expression": "session_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "request_sequence",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_endpoint": {
-          "name": "idx_message_request_endpoint",
-          "columns": [
-            {
-              "expression": "endpoint",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_blocked_by": {
-          "name": "idx_message_request_blocked_by",
-          "columns": [
-            {
-              "expression": "blocked_by",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_provider_id": {
-          "name": "idx_message_request_provider_id",
-          "columns": [
-            {
-              "expression": "provider_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_user_id": {
-          "name": "idx_message_request_user_id",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key": {
-          "name": "idx_message_request_key",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key_created_at_id": {
-          "name": "idx_message_request_key_created_at_id",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_model_active": {
-          "name": "idx_message_request_model_active",
-          "columns": [
-            {
-              "expression": "model",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"model\" IS NOT NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_status_code_active": {
-          "name": "idx_message_request_status_code_active",
-          "columns": [
-            {
-              "expression": "status_code",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"status_code\" IS NOT NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_created_at": {
-          "name": "idx_message_request_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_deleted_at": {
-          "name": "idx_message_request_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.model_prices": {
-      "name": "model_prices",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "model_name": {
-          "name": "model_name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "price_data": {
-          "name": "price_data",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "source": {
-          "name": "source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'litellm'"
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_model_prices_latest": {
-          "name": "idx_model_prices_latest",
-          "columns": [
-            {
-              "expression": "model_name",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_model_name": {
-          "name": "idx_model_prices_model_name",
-          "columns": [
-            {
-              "expression": "model_name",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_created_at": {
-          "name": "idx_model_prices_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_source": {
-          "name": "idx_model_prices_source",
-          "columns": [
-            {
-              "expression": "source",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.notification_settings": {
-      "name": "notification_settings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "enabled": {
-          "name": "enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "use_legacy_mode": {
-          "name": "use_legacy_mode",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "circuit_breaker_enabled": {
-          "name": "circuit_breaker_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "circuit_breaker_webhook": {
-          "name": "circuit_breaker_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_leaderboard_enabled": {
-          "name": "daily_leaderboard_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "daily_leaderboard_webhook": {
-          "name": "daily_leaderboard_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_leaderboard_time": {
-          "name": "daily_leaderboard_time",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'09:00'"
-        },
-        "daily_leaderboard_top_n": {
-          "name": "daily_leaderboard_top_n",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 5
-        },
-        "cost_alert_enabled": {
-          "name": "cost_alert_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "cost_alert_webhook": {
-          "name": "cost_alert_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cost_alert_threshold": {
-          "name": "cost_alert_threshold",
-          "type": "numeric(5, 2)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.80'"
-        },
-        "cost_alert_check_interval": {
-          "name": "cost_alert_check_interval",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 60
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.notification_target_bindings": {
-      "name": "notification_target_bindings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "notification_type": {
-          "name": "notification_type",
-          "type": "notification_type",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "target_id": {
-          "name": "target_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "schedule_cron": {
-          "name": "schedule_cron",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "schedule_timezone": {
-          "name": "schedule_timezone",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "template_override": {
-          "name": "template_override",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "unique_notification_target_binding": {
-          "name": "unique_notification_target_binding",
-          "columns": [
-            {
-              "expression": "notification_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "target_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_notification_bindings_type": {
-          "name": "idx_notification_bindings_type",
-          "columns": [
-            {
-              "expression": "notification_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_notification_bindings_target": {
-          "name": "idx_notification_bindings_target",
-          "columns": [
-            {
-              "expression": "target_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "notification_target_bindings_target_id_webhook_targets_id_fk": {
-          "name": "notification_target_bindings_target_id_webhook_targets_id_fk",
-          "tableFrom": "notification_target_bindings",
-          "tableTo": "webhook_targets",
-          "columnsFrom": [
-            "target_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_endpoint_probe_logs": {
-      "name": "provider_endpoint_probe_logs",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "endpoint_id": {
-          "name": "endpoint_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "source": {
-          "name": "source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'scheduled'"
-        },
-        "ok": {
-          "name": "ok",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "status_code": {
-          "name": "status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "latency_ms": {
-          "name": "latency_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_type": {
-          "name": "error_type",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_message": {
-          "name": "error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_provider_endpoint_probe_logs_endpoint_created_at": {
-          "name": "idx_provider_endpoint_probe_logs_endpoint_created_at",
-          "columns": [
-            {
-              "expression": "endpoint_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoint_probe_logs_created_at": {
-          "name": "idx_provider_endpoint_probe_logs_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "provider_endpoint_probe_logs_endpoint_id_provider_endpoints_id_fk": {
-          "name": "provider_endpoint_probe_logs_endpoint_id_provider_endpoints_id_fk",
-          "tableFrom": "provider_endpoint_probe_logs",
-          "tableTo": "provider_endpoints",
-          "columnsFrom": [
-            "endpoint_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_endpoints": {
-      "name": "provider_endpoints",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "vendor_id": {
-          "name": "vendor_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'claude'"
-        },
-        "url": {
-          "name": "url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "label": {
-          "name": "label",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "sort_order": {
-          "name": "sort_order",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "last_probed_at": {
-          "name": "last_probed_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_ok": {
-          "name": "last_probe_ok",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_status_code": {
-          "name": "last_probe_status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_latency_ms": {
-          "name": "last_probe_latency_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_error_type": {
-          "name": "last_probe_error_type",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_error_message": {
-          "name": "last_probe_error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "uniq_provider_endpoints_vendor_type_url": {
-          "name": "uniq_provider_endpoints_vendor_type_url",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_vendor_type": {
-          "name": "idx_provider_endpoints_vendor_type",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_enabled": {
-          "name": "idx_provider_endpoints_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_pick_enabled": {
-          "name": "idx_provider_endpoints_pick_enabled",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "sort_order",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_created_at": {
-          "name": "idx_provider_endpoints_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_deleted_at": {
-          "name": "idx_provider_endpoints_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "provider_endpoints_vendor_id_provider_vendors_id_fk": {
-          "name": "provider_endpoints_vendor_id_provider_vendors_id_fk",
-          "tableFrom": "provider_endpoints",
-          "tableTo": "provider_vendors",
-          "columnsFrom": [
-            "vendor_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_vendors": {
-      "name": "provider_vendors",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "website_domain": {
-          "name": "website_domain",
-          "type": "varchar(255)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "display_name": {
-          "name": "display_name",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "website_url": {
-          "name": "website_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "favicon_url": {
-          "name": "favicon_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "uniq_provider_vendors_website_domain": {
-          "name": "uniq_provider_vendors_website_domain",
-          "columns": [
-            {
-              "expression": "website_domain",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_vendors_created_at": {
-          "name": "idx_provider_vendors_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.providers": {
-      "name": "providers",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "url": {
-          "name": "url",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_vendor_id": {
-          "name": "provider_vendor_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "weight": {
-          "name": "weight",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 1
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "group_priorities": {
-          "name": "group_priorities",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "cost_multiplier": {
-          "name": "cost_multiplier",
-          "type": "numeric(10, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'1.0'"
-        },
-        "group_tag": {
-          "name": "group_tag",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'claude'"
-        },
-        "preserve_client_ip": {
-          "name": "preserve_client_ip",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "model_redirects": {
-          "name": "model_redirects",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "allowed_models": {
-          "name": "allowed_models",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "join_claude_pool": {
-          "name": "join_claude_pool",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "codex_instructions_strategy": {
-          "name": "codex_instructions_strategy",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'auto'"
-        },
-        "mcp_passthrough_type": {
-          "name": "mcp_passthrough_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'none'"
-        },
-        "mcp_passthrough_url": {
-          "name": "mcp_passthrough_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_daily_usd": {
-          "name": "limit_daily_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "total_cost_reset_at": {
-          "name": "total_cost_reset_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "max_retry_attempts": {
-          "name": "max_retry_attempts",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "circuit_breaker_failure_threshold": {
-          "name": "circuit_breaker_failure_threshold",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 5
-        },
-        "circuit_breaker_open_duration": {
-          "name": "circuit_breaker_open_duration",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 1800000
-        },
-        "circuit_breaker_half_open_success_threshold": {
-          "name": "circuit_breaker_half_open_success_threshold",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 2
-        },
-        "proxy_url": {
-          "name": "proxy_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_fallback_to_direct": {
-          "name": "proxy_fallback_to_direct",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "first_byte_timeout_streaming_ms": {
-          "name": "first_byte_timeout_streaming_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "streaming_idle_timeout_ms": {
-          "name": "streaming_idle_timeout_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "request_timeout_non_streaming_ms": {
-          "name": "request_timeout_non_streaming_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "website_url": {
-          "name": "website_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "favicon_url": {
-          "name": "favicon_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_ttl_preference": {
-          "name": "cache_ttl_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "context_1m_preference": {
-          "name": "context_1m_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_reasoning_effort_preference": {
-          "name": "codex_reasoning_effort_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_reasoning_summary_preference": {
-          "name": "codex_reasoning_summary_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_text_verbosity_preference": {
-          "name": "codex_text_verbosity_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_parallel_tool_calls_preference": {
-          "name": "codex_parallel_tool_calls_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_max_tokens_preference": {
-          "name": "anthropic_max_tokens_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_thinking_budget_preference": {
-          "name": "anthropic_thinking_budget_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_adaptive_thinking": {
-          "name": "anthropic_adaptive_thinking",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "gemini_google_search_preference": {
-          "name": "gemini_google_search_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "tpm": {
-          "name": "tpm",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "rpm": {
-          "name": "rpm",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "rpd": {
-          "name": "rpd",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "cc": {
-          "name": "cc",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_providers_enabled_priority": {
-          "name": "idx_providers_enabled_priority",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "weight",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_group": {
-          "name": "idx_providers_group",
-          "columns": [
-            {
-              "expression": "group_tag",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_vendor_type_url_active": {
-          "name": "idx_providers_vendor_type_url_active",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_created_at": {
-          "name": "idx_providers_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_deleted_at": {
-          "name": "idx_providers_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_vendor_type": {
-          "name": "idx_providers_vendor_type",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "providers_provider_vendor_id_provider_vendors_id_fk": {
-          "name": "providers_provider_vendor_id_provider_vendors_id_fk",
-          "tableFrom": "providers",
-          "tableTo": "provider_vendors",
-          "columnsFrom": [
-            "provider_vendor_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "restrict",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.request_filters": {
-      "name": "request_filters",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "scope": {
-          "name": "scope",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "action": {
-          "name": "action",
-          "type": "varchar(30)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "target": {
-          "name": "target",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "replacement": {
-          "name": "replacement",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "binding_type": {
-          "name": "binding_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'global'"
-        },
-        "provider_ids": {
-          "name": "provider_ids",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "group_tags": {
-          "name": "group_tags",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_request_filters_enabled": {
-          "name": "idx_request_filters_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_scope": {
-          "name": "idx_request_filters_scope",
-          "columns": [
-            {
-              "expression": "scope",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_action": {
-          "name": "idx_request_filters_action",
-          "columns": [
-            {
-              "expression": "action",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_binding": {
-          "name": "idx_request_filters_binding",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "binding_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.sensitive_words": {
-      "name": "sensitive_words",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "word": {
-          "name": "word",
-          "type": "varchar(255)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'contains'"
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_sensitive_words_enabled": {
-          "name": "idx_sensitive_words_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "match_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_sensitive_words_created_at": {
-          "name": "idx_sensitive_words_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.system_settings": {
-      "name": "system_settings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "site_title": {
-          "name": "site_title",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'Claude Code Hub'"
-        },
-        "allow_global_usage_view": {
-          "name": "allow_global_usage_view",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "currency_display": {
-          "name": "currency_display",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'USD'"
-        },
-        "billing_model_source": {
-          "name": "billing_model_source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'original'"
-        },
-        "timezone": {
-          "name": "timezone",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "enable_auto_cleanup": {
-          "name": "enable_auto_cleanup",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "cleanup_retention_days": {
-          "name": "cleanup_retention_days",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 30
-        },
-        "cleanup_schedule": {
-          "name": "cleanup_schedule",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0 2 * * *'"
-        },
-        "cleanup_batch_size": {
-          "name": "cleanup_batch_size",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 10000
-        },
-        "enable_client_version_check": {
-          "name": "enable_client_version_check",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "verbose_provider_error": {
-          "name": "verbose_provider_error",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "enable_http2": {
-          "name": "enable_http2",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "intercept_anthropic_warmup_requests": {
-          "name": "intercept_anthropic_warmup_requests",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "enable_thinking_signature_rectifier": {
-          "name": "enable_thinking_signature_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_thinking_budget_rectifier": {
-          "name": "enable_thinking_budget_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_billing_header_rectifier": {
-          "name": "enable_billing_header_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_codex_session_id_completion": {
-          "name": "enable_codex_session_id_completion",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_claude_metadata_user_id_injection": {
-          "name": "enable_claude_metadata_user_id_injection",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_response_fixer": {
-          "name": "enable_response_fixer",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "response_fixer_config": {
-          "name": "response_fixer_config",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'{\"fixTruncatedJson\":true,\"fixSseFormat\":true,\"fixEncoding\":true,\"maxJsonDepth\":200,\"maxFixSize\":1048576}'::jsonb"
-        },
-        "quota_db_refresh_interval_seconds": {
-          "name": "quota_db_refresh_interval_seconds",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 10
-        },
-        "quota_lease_percent_5h": {
-          "name": "quota_lease_percent_5h",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_daily": {
-          "name": "quota_lease_percent_daily",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_weekly": {
-          "name": "quota_lease_percent_weekly",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_monthly": {
-          "name": "quota_lease_percent_monthly",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_cap_usd": {
-          "name": "quota_lease_cap_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.users": {
-      "name": "users",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "role": {
-          "name": "role",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'user'"
-        },
-        "rpm_limit": {
-          "name": "rpm_limit",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_limit_usd": {
-          "name": "daily_limit_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "provider_group": {
-          "name": "provider_group",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'default'"
-        },
-        "tags": {
-          "name": "tags",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "expires_at": {
-          "name": "expires_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "allowed_clients": {
-          "name": "allowed_clients",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "allowed_models": {
-          "name": "allowed_models",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_users_active_role_sort": {
-          "name": "idx_users_active_role_sort",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "role",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_enabled_expires_at": {
-          "name": "idx_users_enabled_expires_at",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "expires_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_created_at": {
-          "name": "idx_users_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_deleted_at": {
-          "name": "idx_users_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.webhook_targets": {
-      "name": "webhook_targets",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "webhook_provider_type",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "webhook_url": {
-          "name": "webhook_url",
-          "type": "varchar(1024)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "telegram_bot_token": {
-          "name": "telegram_bot_token",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "telegram_chat_id": {
-          "name": "telegram_chat_id",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "dingtalk_secret": {
-          "name": "dingtalk_secret",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "custom_template": {
-          "name": "custom_template",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "custom_headers": {
-          "name": "custom_headers",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_url": {
-          "name": "proxy_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_fallback_to_direct": {
-          "name": "proxy_fallback_to_direct",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "last_test_at": {
-          "name": "last_test_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_test_result": {
-          "name": "last_test_result",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    }
-  },
-  "enums": {
-    "public.daily_reset_mode": {
-      "name": "daily_reset_mode",
-      "schema": "public",
-      "values": [
-        "fixed",
-        "rolling"
-      ]
-    },
-    "public.notification_type": {
-      "name": "notification_type",
-      "schema": "public",
-      "values": [
-        "circuit_breaker",
-        "daily_leaderboard",
-        "cost_alert"
-      ]
-    },
-    "public.webhook_provider_type": {
-      "name": "webhook_provider_type",
-      "schema": "public",
-      "values": [
-        "wechat",
-        "feishu",
-        "dingtalk",
-        "telegram",
-        "custom"
-      ]
-    }
-  },
-  "schemas": {},
-  "sequences": {},
-  "roles": {},
-  "policies": {},
-  "views": {},
-  "_meta": {
-    "columns": {},
-    "schemas": {},
-    "tables": {}
-  }
-}

+ 0 - 3156
drizzle/meta/0070_snapshot.json

@@ -1,3156 +0,0 @@
-{
-  "id": "6195c134-aa4e-4100-9017-495e7d2e2bae",
-  "prevId": "30ac31f0-6588-443f-a197-1c16dab31e1c",
-  "version": "7",
-  "dialect": "postgresql",
-  "tables": {
-    "public.error_rules": {
-      "name": "error_rules",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "pattern": {
-          "name": "pattern",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'regex'"
-        },
-        "category": {
-          "name": "category",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "override_response": {
-          "name": "override_response",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "override_status_code": {
-          "name": "override_status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "is_default": {
-          "name": "is_default",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_error_rules_enabled": {
-          "name": "idx_error_rules_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "unique_pattern": {
-          "name": "unique_pattern",
-          "columns": [
-            {
-              "expression": "pattern",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_category": {
-          "name": "idx_category",
-          "columns": [
-            {
-              "expression": "category",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_match_type": {
-          "name": "idx_match_type",
-          "columns": [
-            {
-              "expression": "match_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.keys": {
-      "name": "keys",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "user_id": {
-          "name": "user_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": true
-        },
-        "expires_at": {
-          "name": "expires_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "can_login_web_ui": {
-          "name": "can_login_web_ui",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_daily_usd": {
-          "name": "limit_daily_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "provider_group": {
-          "name": "provider_group",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'default'"
-        },
-        "cache_ttl_preference": {
-          "name": "cache_ttl_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_keys_user_id": {
-          "name": "idx_keys_user_id",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_created_at": {
-          "name": "idx_keys_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_deleted_at": {
-          "name": "idx_keys_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.message_request": {
-      "name": "message_request",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "provider_id": {
-          "name": "provider_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "user_id": {
-          "name": "user_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "model": {
-          "name": "model",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "duration_ms": {
-          "name": "duration_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cost_usd": {
-          "name": "cost_usd",
-          "type": "numeric(21, 15)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0'"
-        },
-        "cost_multiplier": {
-          "name": "cost_multiplier",
-          "type": "numeric(10, 4)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "session_id": {
-          "name": "session_id",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "request_sequence": {
-          "name": "request_sequence",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 1
-        },
-        "provider_chain": {
-          "name": "provider_chain",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "status_code": {
-          "name": "status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "api_type": {
-          "name": "api_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "endpoint": {
-          "name": "endpoint",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "original_model": {
-          "name": "original_model",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "input_tokens": {
-          "name": "input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "output_tokens": {
-          "name": "output_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "ttfb_ms": {
-          "name": "ttfb_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_input_tokens": {
-          "name": "cache_creation_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_read_input_tokens": {
-          "name": "cache_read_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_5m_input_tokens": {
-          "name": "cache_creation_5m_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_1h_input_tokens": {
-          "name": "cache_creation_1h_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_ttl_applied": {
-          "name": "cache_ttl_applied",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "context_1m_applied": {
-          "name": "context_1m_applied",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "special_settings": {
-          "name": "special_settings",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_message": {
-          "name": "error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_stack": {
-          "name": "error_stack",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_cause": {
-          "name": "error_cause",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "blocked_by": {
-          "name": "blocked_by",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "blocked_reason": {
-          "name": "blocked_reason",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "user_agent": {
-          "name": "user_agent",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "messages_count": {
-          "name": "messages_count",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_message_request_user_date_cost": {
-          "name": "idx_message_request_user_date_cost",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "cost_usd",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_user_query": {
-          "name": "idx_message_request_user_query",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_id": {
-          "name": "idx_message_request_session_id",
-          "columns": [
-            {
-              "expression": "session_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_id_prefix": {
-          "name": "idx_message_request_session_id_prefix",
-          "columns": [
-            {
-              "expression": "\"session_id\" varchar_pattern_ops",
-              "asc": true,
-              "isExpression": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_seq": {
-          "name": "idx_message_request_session_seq",
-          "columns": [
-            {
-              "expression": "session_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "request_sequence",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_endpoint": {
-          "name": "idx_message_request_endpoint",
-          "columns": [
-            {
-              "expression": "endpoint",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_blocked_by": {
-          "name": "idx_message_request_blocked_by",
-          "columns": [
-            {
-              "expression": "blocked_by",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_provider_id": {
-          "name": "idx_message_request_provider_id",
-          "columns": [
-            {
-              "expression": "provider_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_user_id": {
-          "name": "idx_message_request_user_id",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key": {
-          "name": "idx_message_request_key",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key_created_at_id": {
-          "name": "idx_message_request_key_created_at_id",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_created_at_id_active": {
-          "name": "idx_message_request_created_at_id_active",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_model_active": {
-          "name": "idx_message_request_model_active",
-          "columns": [
-            {
-              "expression": "model",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"model\" IS NOT NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_status_code_active": {
-          "name": "idx_message_request_status_code_active",
-          "columns": [
-            {
-              "expression": "status_code",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"status_code\" IS NOT NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_created_at": {
-          "name": "idx_message_request_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_deleted_at": {
-          "name": "idx_message_request_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.model_prices": {
-      "name": "model_prices",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "model_name": {
-          "name": "model_name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "price_data": {
-          "name": "price_data",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "source": {
-          "name": "source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'litellm'"
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_model_prices_latest": {
-          "name": "idx_model_prices_latest",
-          "columns": [
-            {
-              "expression": "model_name",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_model_name": {
-          "name": "idx_model_prices_model_name",
-          "columns": [
-            {
-              "expression": "model_name",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_created_at": {
-          "name": "idx_model_prices_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_source": {
-          "name": "idx_model_prices_source",
-          "columns": [
-            {
-              "expression": "source",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.notification_settings": {
-      "name": "notification_settings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "enabled": {
-          "name": "enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "use_legacy_mode": {
-          "name": "use_legacy_mode",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "circuit_breaker_enabled": {
-          "name": "circuit_breaker_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "circuit_breaker_webhook": {
-          "name": "circuit_breaker_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_leaderboard_enabled": {
-          "name": "daily_leaderboard_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "daily_leaderboard_webhook": {
-          "name": "daily_leaderboard_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_leaderboard_time": {
-          "name": "daily_leaderboard_time",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'09:00'"
-        },
-        "daily_leaderboard_top_n": {
-          "name": "daily_leaderboard_top_n",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 5
-        },
-        "cost_alert_enabled": {
-          "name": "cost_alert_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "cost_alert_webhook": {
-          "name": "cost_alert_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cost_alert_threshold": {
-          "name": "cost_alert_threshold",
-          "type": "numeric(5, 2)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.80'"
-        },
-        "cost_alert_check_interval": {
-          "name": "cost_alert_check_interval",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 60
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.notification_target_bindings": {
-      "name": "notification_target_bindings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "notification_type": {
-          "name": "notification_type",
-          "type": "notification_type",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "target_id": {
-          "name": "target_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "schedule_cron": {
-          "name": "schedule_cron",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "schedule_timezone": {
-          "name": "schedule_timezone",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "template_override": {
-          "name": "template_override",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "unique_notification_target_binding": {
-          "name": "unique_notification_target_binding",
-          "columns": [
-            {
-              "expression": "notification_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "target_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_notification_bindings_type": {
-          "name": "idx_notification_bindings_type",
-          "columns": [
-            {
-              "expression": "notification_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_notification_bindings_target": {
-          "name": "idx_notification_bindings_target",
-          "columns": [
-            {
-              "expression": "target_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "notification_target_bindings_target_id_webhook_targets_id_fk": {
-          "name": "notification_target_bindings_target_id_webhook_targets_id_fk",
-          "tableFrom": "notification_target_bindings",
-          "tableTo": "webhook_targets",
-          "columnsFrom": [
-            "target_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_endpoint_probe_logs": {
-      "name": "provider_endpoint_probe_logs",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "endpoint_id": {
-          "name": "endpoint_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "source": {
-          "name": "source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'scheduled'"
-        },
-        "ok": {
-          "name": "ok",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "status_code": {
-          "name": "status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "latency_ms": {
-          "name": "latency_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_type": {
-          "name": "error_type",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_message": {
-          "name": "error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_provider_endpoint_probe_logs_endpoint_created_at": {
-          "name": "idx_provider_endpoint_probe_logs_endpoint_created_at",
-          "columns": [
-            {
-              "expression": "endpoint_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoint_probe_logs_created_at": {
-          "name": "idx_provider_endpoint_probe_logs_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "provider_endpoint_probe_logs_endpoint_id_provider_endpoints_id_fk": {
-          "name": "provider_endpoint_probe_logs_endpoint_id_provider_endpoints_id_fk",
-          "tableFrom": "provider_endpoint_probe_logs",
-          "tableTo": "provider_endpoints",
-          "columnsFrom": [
-            "endpoint_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_endpoints": {
-      "name": "provider_endpoints",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "vendor_id": {
-          "name": "vendor_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'claude'"
-        },
-        "url": {
-          "name": "url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "label": {
-          "name": "label",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "sort_order": {
-          "name": "sort_order",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "last_probed_at": {
-          "name": "last_probed_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_ok": {
-          "name": "last_probe_ok",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_status_code": {
-          "name": "last_probe_status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_latency_ms": {
-          "name": "last_probe_latency_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_error_type": {
-          "name": "last_probe_error_type",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_error_message": {
-          "name": "last_probe_error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "uniq_provider_endpoints_vendor_type_url": {
-          "name": "uniq_provider_endpoints_vendor_type_url",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_vendor_type": {
-          "name": "idx_provider_endpoints_vendor_type",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_enabled": {
-          "name": "idx_provider_endpoints_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_pick_enabled": {
-          "name": "idx_provider_endpoints_pick_enabled",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "sort_order",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_created_at": {
-          "name": "idx_provider_endpoints_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_deleted_at": {
-          "name": "idx_provider_endpoints_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "provider_endpoints_vendor_id_provider_vendors_id_fk": {
-          "name": "provider_endpoints_vendor_id_provider_vendors_id_fk",
-          "tableFrom": "provider_endpoints",
-          "tableTo": "provider_vendors",
-          "columnsFrom": [
-            "vendor_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_vendors": {
-      "name": "provider_vendors",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "website_domain": {
-          "name": "website_domain",
-          "type": "varchar(255)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "display_name": {
-          "name": "display_name",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "website_url": {
-          "name": "website_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "favicon_url": {
-          "name": "favicon_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "uniq_provider_vendors_website_domain": {
-          "name": "uniq_provider_vendors_website_domain",
-          "columns": [
-            {
-              "expression": "website_domain",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_vendors_created_at": {
-          "name": "idx_provider_vendors_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.providers": {
-      "name": "providers",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "url": {
-          "name": "url",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_vendor_id": {
-          "name": "provider_vendor_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "weight": {
-          "name": "weight",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 1
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "group_priorities": {
-          "name": "group_priorities",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "cost_multiplier": {
-          "name": "cost_multiplier",
-          "type": "numeric(10, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'1.0'"
-        },
-        "group_tag": {
-          "name": "group_tag",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'claude'"
-        },
-        "preserve_client_ip": {
-          "name": "preserve_client_ip",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "model_redirects": {
-          "name": "model_redirects",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "allowed_models": {
-          "name": "allowed_models",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "join_claude_pool": {
-          "name": "join_claude_pool",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "codex_instructions_strategy": {
-          "name": "codex_instructions_strategy",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'auto'"
-        },
-        "mcp_passthrough_type": {
-          "name": "mcp_passthrough_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'none'"
-        },
-        "mcp_passthrough_url": {
-          "name": "mcp_passthrough_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_daily_usd": {
-          "name": "limit_daily_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "total_cost_reset_at": {
-          "name": "total_cost_reset_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "max_retry_attempts": {
-          "name": "max_retry_attempts",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "circuit_breaker_failure_threshold": {
-          "name": "circuit_breaker_failure_threshold",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 5
-        },
-        "circuit_breaker_open_duration": {
-          "name": "circuit_breaker_open_duration",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 1800000
-        },
-        "circuit_breaker_half_open_success_threshold": {
-          "name": "circuit_breaker_half_open_success_threshold",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 2
-        },
-        "proxy_url": {
-          "name": "proxy_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_fallback_to_direct": {
-          "name": "proxy_fallback_to_direct",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "first_byte_timeout_streaming_ms": {
-          "name": "first_byte_timeout_streaming_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "streaming_idle_timeout_ms": {
-          "name": "streaming_idle_timeout_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "request_timeout_non_streaming_ms": {
-          "name": "request_timeout_non_streaming_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "website_url": {
-          "name": "website_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "favicon_url": {
-          "name": "favicon_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_ttl_preference": {
-          "name": "cache_ttl_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "context_1m_preference": {
-          "name": "context_1m_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_reasoning_effort_preference": {
-          "name": "codex_reasoning_effort_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_reasoning_summary_preference": {
-          "name": "codex_reasoning_summary_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_text_verbosity_preference": {
-          "name": "codex_text_verbosity_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_parallel_tool_calls_preference": {
-          "name": "codex_parallel_tool_calls_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_max_tokens_preference": {
-          "name": "anthropic_max_tokens_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_thinking_budget_preference": {
-          "name": "anthropic_thinking_budget_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_adaptive_thinking": {
-          "name": "anthropic_adaptive_thinking",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "gemini_google_search_preference": {
-          "name": "gemini_google_search_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "tpm": {
-          "name": "tpm",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "rpm": {
-          "name": "rpm",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "rpd": {
-          "name": "rpd",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "cc": {
-          "name": "cc",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_providers_enabled_priority": {
-          "name": "idx_providers_enabled_priority",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "weight",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_group": {
-          "name": "idx_providers_group",
-          "columns": [
-            {
-              "expression": "group_tag",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_vendor_type_url_active": {
-          "name": "idx_providers_vendor_type_url_active",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_created_at": {
-          "name": "idx_providers_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_deleted_at": {
-          "name": "idx_providers_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_vendor_type": {
-          "name": "idx_providers_vendor_type",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "providers_provider_vendor_id_provider_vendors_id_fk": {
-          "name": "providers_provider_vendor_id_provider_vendors_id_fk",
-          "tableFrom": "providers",
-          "tableTo": "provider_vendors",
-          "columnsFrom": [
-            "provider_vendor_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "restrict",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.request_filters": {
-      "name": "request_filters",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "scope": {
-          "name": "scope",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "action": {
-          "name": "action",
-          "type": "varchar(30)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "target": {
-          "name": "target",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "replacement": {
-          "name": "replacement",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "binding_type": {
-          "name": "binding_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'global'"
-        },
-        "provider_ids": {
-          "name": "provider_ids",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "group_tags": {
-          "name": "group_tags",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_request_filters_enabled": {
-          "name": "idx_request_filters_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_scope": {
-          "name": "idx_request_filters_scope",
-          "columns": [
-            {
-              "expression": "scope",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_action": {
-          "name": "idx_request_filters_action",
-          "columns": [
-            {
-              "expression": "action",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_binding": {
-          "name": "idx_request_filters_binding",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "binding_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.sensitive_words": {
-      "name": "sensitive_words",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "word": {
-          "name": "word",
-          "type": "varchar(255)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'contains'"
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_sensitive_words_enabled": {
-          "name": "idx_sensitive_words_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "match_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_sensitive_words_created_at": {
-          "name": "idx_sensitive_words_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.system_settings": {
-      "name": "system_settings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "site_title": {
-          "name": "site_title",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'Claude Code Hub'"
-        },
-        "allow_global_usage_view": {
-          "name": "allow_global_usage_view",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "currency_display": {
-          "name": "currency_display",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'USD'"
-        },
-        "billing_model_source": {
-          "name": "billing_model_source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'original'"
-        },
-        "timezone": {
-          "name": "timezone",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "enable_auto_cleanup": {
-          "name": "enable_auto_cleanup",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "cleanup_retention_days": {
-          "name": "cleanup_retention_days",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 30
-        },
-        "cleanup_schedule": {
-          "name": "cleanup_schedule",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0 2 * * *'"
-        },
-        "cleanup_batch_size": {
-          "name": "cleanup_batch_size",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 10000
-        },
-        "enable_client_version_check": {
-          "name": "enable_client_version_check",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "verbose_provider_error": {
-          "name": "verbose_provider_error",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "enable_http2": {
-          "name": "enable_http2",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "intercept_anthropic_warmup_requests": {
-          "name": "intercept_anthropic_warmup_requests",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "enable_thinking_signature_rectifier": {
-          "name": "enable_thinking_signature_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_thinking_budget_rectifier": {
-          "name": "enable_thinking_budget_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_billing_header_rectifier": {
-          "name": "enable_billing_header_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_codex_session_id_completion": {
-          "name": "enable_codex_session_id_completion",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_claude_metadata_user_id_injection": {
-          "name": "enable_claude_metadata_user_id_injection",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_response_fixer": {
-          "name": "enable_response_fixer",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "response_fixer_config": {
-          "name": "response_fixer_config",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'{\"fixTruncatedJson\":true,\"fixSseFormat\":true,\"fixEncoding\":true,\"maxJsonDepth\":200,\"maxFixSize\":1048576}'::jsonb"
-        },
-        "quota_db_refresh_interval_seconds": {
-          "name": "quota_db_refresh_interval_seconds",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 10
-        },
-        "quota_lease_percent_5h": {
-          "name": "quota_lease_percent_5h",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_daily": {
-          "name": "quota_lease_percent_daily",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_weekly": {
-          "name": "quota_lease_percent_weekly",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_monthly": {
-          "name": "quota_lease_percent_monthly",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_cap_usd": {
-          "name": "quota_lease_cap_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.users": {
-      "name": "users",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "role": {
-          "name": "role",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'user'"
-        },
-        "rpm_limit": {
-          "name": "rpm_limit",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_limit_usd": {
-          "name": "daily_limit_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "provider_group": {
-          "name": "provider_group",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'default'"
-        },
-        "tags": {
-          "name": "tags",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "expires_at": {
-          "name": "expires_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "allowed_clients": {
-          "name": "allowed_clients",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "allowed_models": {
-          "name": "allowed_models",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_users_active_role_sort": {
-          "name": "idx_users_active_role_sort",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "role",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_enabled_expires_at": {
-          "name": "idx_users_enabled_expires_at",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "expires_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_tags_gin": {
-          "name": "idx_users_tags_gin",
-          "columns": [
-            {
-              "expression": "tags",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "gin",
-          "with": {}
-        },
-        "idx_users_created_at": {
-          "name": "idx_users_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_deleted_at": {
-          "name": "idx_users_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.webhook_targets": {
-      "name": "webhook_targets",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "webhook_provider_type",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "webhook_url": {
-          "name": "webhook_url",
-          "type": "varchar(1024)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "telegram_bot_token": {
-          "name": "telegram_bot_token",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "telegram_chat_id": {
-          "name": "telegram_chat_id",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "dingtalk_secret": {
-          "name": "dingtalk_secret",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "custom_template": {
-          "name": "custom_template",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "custom_headers": {
-          "name": "custom_headers",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_url": {
-          "name": "proxy_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_fallback_to_direct": {
-          "name": "proxy_fallback_to_direct",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "last_test_at": {
-          "name": "last_test_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_test_result": {
-          "name": "last_test_result",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    }
-  },
-  "enums": {
-    "public.daily_reset_mode": {
-      "name": "daily_reset_mode",
-      "schema": "public",
-      "values": [
-        "fixed",
-        "rolling"
-      ]
-    },
-    "public.notification_type": {
-      "name": "notification_type",
-      "schema": "public",
-      "values": [
-        "circuit_breaker",
-        "daily_leaderboard",
-        "cost_alert"
-      ]
-    },
-    "public.webhook_provider_type": {
-      "name": "webhook_provider_type",
-      "schema": "public",
-      "values": [
-        "wechat",
-        "feishu",
-        "dingtalk",
-        "telegram",
-        "custom"
-      ]
-    }
-  },
-  "schemas": {},
-  "sequences": {},
-  "roles": {},
-  "policies": {},
-  "views": {},
-  "_meta": {
-    "columns": {},
-    "schemas": {},
-    "tables": {}
-  }
-}

+ 0 - 3171
drizzle/meta/0071_snapshot.json

@@ -1,3171 +0,0 @@
-{
-  "id": "8ca11370-02da-476b-873f-6bee3a7fe4ad",
-  "prevId": "6195c134-aa4e-4100-9017-495e7d2e2bae",
-  "version": "7",
-  "dialect": "postgresql",
-  "tables": {
-    "public.error_rules": {
-      "name": "error_rules",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "pattern": {
-          "name": "pattern",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'regex'"
-        },
-        "category": {
-          "name": "category",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "override_response": {
-          "name": "override_response",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "override_status_code": {
-          "name": "override_status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "is_default": {
-          "name": "is_default",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_error_rules_enabled": {
-          "name": "idx_error_rules_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "unique_pattern": {
-          "name": "unique_pattern",
-          "columns": [
-            {
-              "expression": "pattern",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_category": {
-          "name": "idx_category",
-          "columns": [
-            {
-              "expression": "category",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_match_type": {
-          "name": "idx_match_type",
-          "columns": [
-            {
-              "expression": "match_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.keys": {
-      "name": "keys",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "user_id": {
-          "name": "user_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": true
-        },
-        "expires_at": {
-          "name": "expires_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "can_login_web_ui": {
-          "name": "can_login_web_ui",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_daily_usd": {
-          "name": "limit_daily_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "provider_group": {
-          "name": "provider_group",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'default'"
-        },
-        "cache_ttl_preference": {
-          "name": "cache_ttl_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_keys_user_id": {
-          "name": "idx_keys_user_id",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_key": {
-          "name": "idx_keys_key",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_created_at": {
-          "name": "idx_keys_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_deleted_at": {
-          "name": "idx_keys_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.message_request": {
-      "name": "message_request",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "provider_id": {
-          "name": "provider_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "user_id": {
-          "name": "user_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "model": {
-          "name": "model",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "duration_ms": {
-          "name": "duration_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cost_usd": {
-          "name": "cost_usd",
-          "type": "numeric(21, 15)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0'"
-        },
-        "cost_multiplier": {
-          "name": "cost_multiplier",
-          "type": "numeric(10, 4)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "session_id": {
-          "name": "session_id",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "request_sequence": {
-          "name": "request_sequence",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 1
-        },
-        "provider_chain": {
-          "name": "provider_chain",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "status_code": {
-          "name": "status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "api_type": {
-          "name": "api_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "endpoint": {
-          "name": "endpoint",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "original_model": {
-          "name": "original_model",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "input_tokens": {
-          "name": "input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "output_tokens": {
-          "name": "output_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "ttfb_ms": {
-          "name": "ttfb_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_input_tokens": {
-          "name": "cache_creation_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_read_input_tokens": {
-          "name": "cache_read_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_5m_input_tokens": {
-          "name": "cache_creation_5m_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_1h_input_tokens": {
-          "name": "cache_creation_1h_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_ttl_applied": {
-          "name": "cache_ttl_applied",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "context_1m_applied": {
-          "name": "context_1m_applied",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "special_settings": {
-          "name": "special_settings",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_message": {
-          "name": "error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_stack": {
-          "name": "error_stack",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_cause": {
-          "name": "error_cause",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "blocked_by": {
-          "name": "blocked_by",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "blocked_reason": {
-          "name": "blocked_reason",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "user_agent": {
-          "name": "user_agent",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "messages_count": {
-          "name": "messages_count",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_message_request_user_date_cost": {
-          "name": "idx_message_request_user_date_cost",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "cost_usd",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_user_query": {
-          "name": "idx_message_request_user_query",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_id": {
-          "name": "idx_message_request_session_id",
-          "columns": [
-            {
-              "expression": "session_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_id_prefix": {
-          "name": "idx_message_request_session_id_prefix",
-          "columns": [
-            {
-              "expression": "\"session_id\" varchar_pattern_ops",
-              "asc": true,
-              "isExpression": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_seq": {
-          "name": "idx_message_request_session_seq",
-          "columns": [
-            {
-              "expression": "session_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "request_sequence",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_endpoint": {
-          "name": "idx_message_request_endpoint",
-          "columns": [
-            {
-              "expression": "endpoint",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_blocked_by": {
-          "name": "idx_message_request_blocked_by",
-          "columns": [
-            {
-              "expression": "blocked_by",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_provider_id": {
-          "name": "idx_message_request_provider_id",
-          "columns": [
-            {
-              "expression": "provider_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_user_id": {
-          "name": "idx_message_request_user_id",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key": {
-          "name": "idx_message_request_key",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key_created_at_id": {
-          "name": "idx_message_request_key_created_at_id",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_created_at_id_active": {
-          "name": "idx_message_request_created_at_id_active",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_model_active": {
-          "name": "idx_message_request_model_active",
-          "columns": [
-            {
-              "expression": "model",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"model\" IS NOT NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_status_code_active": {
-          "name": "idx_message_request_status_code_active",
-          "columns": [
-            {
-              "expression": "status_code",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"status_code\" IS NOT NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_created_at": {
-          "name": "idx_message_request_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_deleted_at": {
-          "name": "idx_message_request_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.model_prices": {
-      "name": "model_prices",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "model_name": {
-          "name": "model_name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "price_data": {
-          "name": "price_data",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "source": {
-          "name": "source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'litellm'"
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_model_prices_latest": {
-          "name": "idx_model_prices_latest",
-          "columns": [
-            {
-              "expression": "model_name",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_model_name": {
-          "name": "idx_model_prices_model_name",
-          "columns": [
-            {
-              "expression": "model_name",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_created_at": {
-          "name": "idx_model_prices_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_source": {
-          "name": "idx_model_prices_source",
-          "columns": [
-            {
-              "expression": "source",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.notification_settings": {
-      "name": "notification_settings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "enabled": {
-          "name": "enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "use_legacy_mode": {
-          "name": "use_legacy_mode",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "circuit_breaker_enabled": {
-          "name": "circuit_breaker_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "circuit_breaker_webhook": {
-          "name": "circuit_breaker_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_leaderboard_enabled": {
-          "name": "daily_leaderboard_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "daily_leaderboard_webhook": {
-          "name": "daily_leaderboard_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_leaderboard_time": {
-          "name": "daily_leaderboard_time",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'09:00'"
-        },
-        "daily_leaderboard_top_n": {
-          "name": "daily_leaderboard_top_n",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 5
-        },
-        "cost_alert_enabled": {
-          "name": "cost_alert_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "cost_alert_webhook": {
-          "name": "cost_alert_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cost_alert_threshold": {
-          "name": "cost_alert_threshold",
-          "type": "numeric(5, 2)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.80'"
-        },
-        "cost_alert_check_interval": {
-          "name": "cost_alert_check_interval",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 60
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.notification_target_bindings": {
-      "name": "notification_target_bindings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "notification_type": {
-          "name": "notification_type",
-          "type": "notification_type",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "target_id": {
-          "name": "target_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "schedule_cron": {
-          "name": "schedule_cron",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "schedule_timezone": {
-          "name": "schedule_timezone",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "template_override": {
-          "name": "template_override",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "unique_notification_target_binding": {
-          "name": "unique_notification_target_binding",
-          "columns": [
-            {
-              "expression": "notification_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "target_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_notification_bindings_type": {
-          "name": "idx_notification_bindings_type",
-          "columns": [
-            {
-              "expression": "notification_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_notification_bindings_target": {
-          "name": "idx_notification_bindings_target",
-          "columns": [
-            {
-              "expression": "target_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "notification_target_bindings_target_id_webhook_targets_id_fk": {
-          "name": "notification_target_bindings_target_id_webhook_targets_id_fk",
-          "tableFrom": "notification_target_bindings",
-          "tableTo": "webhook_targets",
-          "columnsFrom": [
-            "target_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_endpoint_probe_logs": {
-      "name": "provider_endpoint_probe_logs",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "endpoint_id": {
-          "name": "endpoint_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "source": {
-          "name": "source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'scheduled'"
-        },
-        "ok": {
-          "name": "ok",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "status_code": {
-          "name": "status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "latency_ms": {
-          "name": "latency_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_type": {
-          "name": "error_type",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_message": {
-          "name": "error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_provider_endpoint_probe_logs_endpoint_created_at": {
-          "name": "idx_provider_endpoint_probe_logs_endpoint_created_at",
-          "columns": [
-            {
-              "expression": "endpoint_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoint_probe_logs_created_at": {
-          "name": "idx_provider_endpoint_probe_logs_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "provider_endpoint_probe_logs_endpoint_id_provider_endpoints_id_fk": {
-          "name": "provider_endpoint_probe_logs_endpoint_id_provider_endpoints_id_fk",
-          "tableFrom": "provider_endpoint_probe_logs",
-          "tableTo": "provider_endpoints",
-          "columnsFrom": [
-            "endpoint_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_endpoints": {
-      "name": "provider_endpoints",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "vendor_id": {
-          "name": "vendor_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'claude'"
-        },
-        "url": {
-          "name": "url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "label": {
-          "name": "label",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "sort_order": {
-          "name": "sort_order",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "last_probed_at": {
-          "name": "last_probed_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_ok": {
-          "name": "last_probe_ok",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_status_code": {
-          "name": "last_probe_status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_latency_ms": {
-          "name": "last_probe_latency_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_error_type": {
-          "name": "last_probe_error_type",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_error_message": {
-          "name": "last_probe_error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "uniq_provider_endpoints_vendor_type_url": {
-          "name": "uniq_provider_endpoints_vendor_type_url",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_vendor_type": {
-          "name": "idx_provider_endpoints_vendor_type",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_enabled": {
-          "name": "idx_provider_endpoints_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_pick_enabled": {
-          "name": "idx_provider_endpoints_pick_enabled",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "sort_order",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_created_at": {
-          "name": "idx_provider_endpoints_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_deleted_at": {
-          "name": "idx_provider_endpoints_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "provider_endpoints_vendor_id_provider_vendors_id_fk": {
-          "name": "provider_endpoints_vendor_id_provider_vendors_id_fk",
-          "tableFrom": "provider_endpoints",
-          "tableTo": "provider_vendors",
-          "columnsFrom": [
-            "vendor_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_vendors": {
-      "name": "provider_vendors",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "website_domain": {
-          "name": "website_domain",
-          "type": "varchar(255)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "display_name": {
-          "name": "display_name",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "website_url": {
-          "name": "website_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "favicon_url": {
-          "name": "favicon_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "uniq_provider_vendors_website_domain": {
-          "name": "uniq_provider_vendors_website_domain",
-          "columns": [
-            {
-              "expression": "website_domain",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_vendors_created_at": {
-          "name": "idx_provider_vendors_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.providers": {
-      "name": "providers",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "url": {
-          "name": "url",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_vendor_id": {
-          "name": "provider_vendor_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "weight": {
-          "name": "weight",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 1
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "group_priorities": {
-          "name": "group_priorities",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "cost_multiplier": {
-          "name": "cost_multiplier",
-          "type": "numeric(10, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'1.0'"
-        },
-        "group_tag": {
-          "name": "group_tag",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'claude'"
-        },
-        "preserve_client_ip": {
-          "name": "preserve_client_ip",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "model_redirects": {
-          "name": "model_redirects",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "allowed_models": {
-          "name": "allowed_models",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "join_claude_pool": {
-          "name": "join_claude_pool",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "codex_instructions_strategy": {
-          "name": "codex_instructions_strategy",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'auto'"
-        },
-        "mcp_passthrough_type": {
-          "name": "mcp_passthrough_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'none'"
-        },
-        "mcp_passthrough_url": {
-          "name": "mcp_passthrough_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_daily_usd": {
-          "name": "limit_daily_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "total_cost_reset_at": {
-          "name": "total_cost_reset_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "max_retry_attempts": {
-          "name": "max_retry_attempts",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "circuit_breaker_failure_threshold": {
-          "name": "circuit_breaker_failure_threshold",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 5
-        },
-        "circuit_breaker_open_duration": {
-          "name": "circuit_breaker_open_duration",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 1800000
-        },
-        "circuit_breaker_half_open_success_threshold": {
-          "name": "circuit_breaker_half_open_success_threshold",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 2
-        },
-        "proxy_url": {
-          "name": "proxy_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_fallback_to_direct": {
-          "name": "proxy_fallback_to_direct",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "first_byte_timeout_streaming_ms": {
-          "name": "first_byte_timeout_streaming_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "streaming_idle_timeout_ms": {
-          "name": "streaming_idle_timeout_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "request_timeout_non_streaming_ms": {
-          "name": "request_timeout_non_streaming_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "website_url": {
-          "name": "website_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "favicon_url": {
-          "name": "favicon_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_ttl_preference": {
-          "name": "cache_ttl_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "context_1m_preference": {
-          "name": "context_1m_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_reasoning_effort_preference": {
-          "name": "codex_reasoning_effort_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_reasoning_summary_preference": {
-          "name": "codex_reasoning_summary_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_text_verbosity_preference": {
-          "name": "codex_text_verbosity_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_parallel_tool_calls_preference": {
-          "name": "codex_parallel_tool_calls_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_max_tokens_preference": {
-          "name": "anthropic_max_tokens_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_thinking_budget_preference": {
-          "name": "anthropic_thinking_budget_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_adaptive_thinking": {
-          "name": "anthropic_adaptive_thinking",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "gemini_google_search_preference": {
-          "name": "gemini_google_search_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "tpm": {
-          "name": "tpm",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "rpm": {
-          "name": "rpm",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "rpd": {
-          "name": "rpd",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "cc": {
-          "name": "cc",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_providers_enabled_priority": {
-          "name": "idx_providers_enabled_priority",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "weight",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_group": {
-          "name": "idx_providers_group",
-          "columns": [
-            {
-              "expression": "group_tag",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_vendor_type_url_active": {
-          "name": "idx_providers_vendor_type_url_active",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_created_at": {
-          "name": "idx_providers_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_deleted_at": {
-          "name": "idx_providers_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_vendor_type": {
-          "name": "idx_providers_vendor_type",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "providers_provider_vendor_id_provider_vendors_id_fk": {
-          "name": "providers_provider_vendor_id_provider_vendors_id_fk",
-          "tableFrom": "providers",
-          "tableTo": "provider_vendors",
-          "columnsFrom": [
-            "provider_vendor_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "restrict",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.request_filters": {
-      "name": "request_filters",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "scope": {
-          "name": "scope",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "action": {
-          "name": "action",
-          "type": "varchar(30)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "target": {
-          "name": "target",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "replacement": {
-          "name": "replacement",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "binding_type": {
-          "name": "binding_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'global'"
-        },
-        "provider_ids": {
-          "name": "provider_ids",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "group_tags": {
-          "name": "group_tags",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_request_filters_enabled": {
-          "name": "idx_request_filters_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_scope": {
-          "name": "idx_request_filters_scope",
-          "columns": [
-            {
-              "expression": "scope",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_action": {
-          "name": "idx_request_filters_action",
-          "columns": [
-            {
-              "expression": "action",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_binding": {
-          "name": "idx_request_filters_binding",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "binding_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.sensitive_words": {
-      "name": "sensitive_words",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "word": {
-          "name": "word",
-          "type": "varchar(255)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'contains'"
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_sensitive_words_enabled": {
-          "name": "idx_sensitive_words_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "match_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_sensitive_words_created_at": {
-          "name": "idx_sensitive_words_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.system_settings": {
-      "name": "system_settings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "site_title": {
-          "name": "site_title",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'Claude Code Hub'"
-        },
-        "allow_global_usage_view": {
-          "name": "allow_global_usage_view",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "currency_display": {
-          "name": "currency_display",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'USD'"
-        },
-        "billing_model_source": {
-          "name": "billing_model_source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'original'"
-        },
-        "timezone": {
-          "name": "timezone",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "enable_auto_cleanup": {
-          "name": "enable_auto_cleanup",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "cleanup_retention_days": {
-          "name": "cleanup_retention_days",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 30
-        },
-        "cleanup_schedule": {
-          "name": "cleanup_schedule",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0 2 * * *'"
-        },
-        "cleanup_batch_size": {
-          "name": "cleanup_batch_size",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 10000
-        },
-        "enable_client_version_check": {
-          "name": "enable_client_version_check",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "verbose_provider_error": {
-          "name": "verbose_provider_error",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "enable_http2": {
-          "name": "enable_http2",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "intercept_anthropic_warmup_requests": {
-          "name": "intercept_anthropic_warmup_requests",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "enable_thinking_signature_rectifier": {
-          "name": "enable_thinking_signature_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_thinking_budget_rectifier": {
-          "name": "enable_thinking_budget_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_billing_header_rectifier": {
-          "name": "enable_billing_header_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_codex_session_id_completion": {
-          "name": "enable_codex_session_id_completion",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_claude_metadata_user_id_injection": {
-          "name": "enable_claude_metadata_user_id_injection",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_response_fixer": {
-          "name": "enable_response_fixer",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "response_fixer_config": {
-          "name": "response_fixer_config",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'{\"fixTruncatedJson\":true,\"fixSseFormat\":true,\"fixEncoding\":true,\"maxJsonDepth\":200,\"maxFixSize\":1048576}'::jsonb"
-        },
-        "quota_db_refresh_interval_seconds": {
-          "name": "quota_db_refresh_interval_seconds",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 10
-        },
-        "quota_lease_percent_5h": {
-          "name": "quota_lease_percent_5h",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_daily": {
-          "name": "quota_lease_percent_daily",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_weekly": {
-          "name": "quota_lease_percent_weekly",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_monthly": {
-          "name": "quota_lease_percent_monthly",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_cap_usd": {
-          "name": "quota_lease_cap_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.users": {
-      "name": "users",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "role": {
-          "name": "role",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'user'"
-        },
-        "rpm_limit": {
-          "name": "rpm_limit",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_limit_usd": {
-          "name": "daily_limit_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "provider_group": {
-          "name": "provider_group",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'default'"
-        },
-        "tags": {
-          "name": "tags",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "expires_at": {
-          "name": "expires_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "allowed_clients": {
-          "name": "allowed_clients",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "allowed_models": {
-          "name": "allowed_models",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_users_active_role_sort": {
-          "name": "idx_users_active_role_sort",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "role",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_enabled_expires_at": {
-          "name": "idx_users_enabled_expires_at",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "expires_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_tags_gin": {
-          "name": "idx_users_tags_gin",
-          "columns": [
-            {
-              "expression": "tags",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "gin",
-          "with": {}
-        },
-        "idx_users_created_at": {
-          "name": "idx_users_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_deleted_at": {
-          "name": "idx_users_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.webhook_targets": {
-      "name": "webhook_targets",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "webhook_provider_type",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "webhook_url": {
-          "name": "webhook_url",
-          "type": "varchar(1024)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "telegram_bot_token": {
-          "name": "telegram_bot_token",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "telegram_chat_id": {
-          "name": "telegram_chat_id",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "dingtalk_secret": {
-          "name": "dingtalk_secret",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "custom_template": {
-          "name": "custom_template",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "custom_headers": {
-          "name": "custom_headers",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_url": {
-          "name": "proxy_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_fallback_to_direct": {
-          "name": "proxy_fallback_to_direct",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "last_test_at": {
-          "name": "last_test_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_test_result": {
-          "name": "last_test_result",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    }
-  },
-  "enums": {
-    "public.daily_reset_mode": {
-      "name": "daily_reset_mode",
-      "schema": "public",
-      "values": [
-        "fixed",
-        "rolling"
-      ]
-    },
-    "public.notification_type": {
-      "name": "notification_type",
-      "schema": "public",
-      "values": [
-        "circuit_breaker",
-        "daily_leaderboard",
-        "cost_alert"
-      ]
-    },
-    "public.webhook_provider_type": {
-      "name": "webhook_provider_type",
-      "schema": "public",
-      "values": [
-        "wechat",
-        "feishu",
-        "dingtalk",
-        "telegram",
-        "custom"
-      ]
-    }
-  },
-  "schemas": {},
-  "sequences": {},
-  "roles": {},
-  "policies": {},
-  "views": {},
-  "_meta": {
-    "columns": {},
-    "schemas": {},
-    "tables": {}
-  }
-}

+ 0 - 3215
drizzle/meta/0072_snapshot.json

@@ -1,3215 +0,0 @@
-{
-  "id": "f9f36628-8ee9-464a-94da-8d6ef636ebdb",
-  "prevId": "8ca11370-02da-476b-873f-6bee3a7fe4ad",
-  "version": "7",
-  "dialect": "postgresql",
-  "tables": {
-    "public.error_rules": {
-      "name": "error_rules",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "pattern": {
-          "name": "pattern",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'regex'"
-        },
-        "category": {
-          "name": "category",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "override_response": {
-          "name": "override_response",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "override_status_code": {
-          "name": "override_status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "is_default": {
-          "name": "is_default",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_error_rules_enabled": {
-          "name": "idx_error_rules_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "unique_pattern": {
-          "name": "unique_pattern",
-          "columns": [
-            {
-              "expression": "pattern",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_category": {
-          "name": "idx_category",
-          "columns": [
-            {
-              "expression": "category",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_match_type": {
-          "name": "idx_match_type",
-          "columns": [
-            {
-              "expression": "match_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.keys": {
-      "name": "keys",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "user_id": {
-          "name": "user_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": true
-        },
-        "expires_at": {
-          "name": "expires_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "can_login_web_ui": {
-          "name": "can_login_web_ui",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_daily_usd": {
-          "name": "limit_daily_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "provider_group": {
-          "name": "provider_group",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'default'"
-        },
-        "cache_ttl_preference": {
-          "name": "cache_ttl_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_keys_user_id": {
-          "name": "idx_keys_user_id",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_key": {
-          "name": "idx_keys_key",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_created_at": {
-          "name": "idx_keys_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_deleted_at": {
-          "name": "idx_keys_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.message_request": {
-      "name": "message_request",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "provider_id": {
-          "name": "provider_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "user_id": {
-          "name": "user_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "model": {
-          "name": "model",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "duration_ms": {
-          "name": "duration_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cost_usd": {
-          "name": "cost_usd",
-          "type": "numeric(21, 15)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0'"
-        },
-        "cost_multiplier": {
-          "name": "cost_multiplier",
-          "type": "numeric(10, 4)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "session_id": {
-          "name": "session_id",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "request_sequence": {
-          "name": "request_sequence",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 1
-        },
-        "provider_chain": {
-          "name": "provider_chain",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "status_code": {
-          "name": "status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "api_type": {
-          "name": "api_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "endpoint": {
-          "name": "endpoint",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "original_model": {
-          "name": "original_model",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "input_tokens": {
-          "name": "input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "output_tokens": {
-          "name": "output_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "ttfb_ms": {
-          "name": "ttfb_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_input_tokens": {
-          "name": "cache_creation_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_read_input_tokens": {
-          "name": "cache_read_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_5m_input_tokens": {
-          "name": "cache_creation_5m_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_1h_input_tokens": {
-          "name": "cache_creation_1h_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_ttl_applied": {
-          "name": "cache_ttl_applied",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "context_1m_applied": {
-          "name": "context_1m_applied",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "special_settings": {
-          "name": "special_settings",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_message": {
-          "name": "error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_stack": {
-          "name": "error_stack",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_cause": {
-          "name": "error_cause",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "blocked_by": {
-          "name": "blocked_by",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "blocked_reason": {
-          "name": "blocked_reason",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "user_agent": {
-          "name": "user_agent",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "messages_count": {
-          "name": "messages_count",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_message_request_user_date_cost": {
-          "name": "idx_message_request_user_date_cost",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "cost_usd",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_user_query": {
-          "name": "idx_message_request_user_query",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_id": {
-          "name": "idx_message_request_session_id",
-          "columns": [
-            {
-              "expression": "session_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_id_prefix": {
-          "name": "idx_message_request_session_id_prefix",
-          "columns": [
-            {
-              "expression": "\"session_id\" varchar_pattern_ops",
-              "asc": true,
-              "isExpression": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_seq": {
-          "name": "idx_message_request_session_seq",
-          "columns": [
-            {
-              "expression": "session_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "request_sequence",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_endpoint": {
-          "name": "idx_message_request_endpoint",
-          "columns": [
-            {
-              "expression": "endpoint",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_blocked_by": {
-          "name": "idx_message_request_blocked_by",
-          "columns": [
-            {
-              "expression": "blocked_by",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_provider_id": {
-          "name": "idx_message_request_provider_id",
-          "columns": [
-            {
-              "expression": "provider_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_user_id": {
-          "name": "idx_message_request_user_id",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key": {
-          "name": "idx_message_request_key",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key_created_at_id": {
-          "name": "idx_message_request_key_created_at_id",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key_model_active": {
-          "name": "idx_message_request_key_model_active",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "model",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"model\" IS NOT NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key_endpoint_active": {
-          "name": "idx_message_request_key_endpoint_active",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "endpoint",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"endpoint\" IS NOT NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_created_at_id_active": {
-          "name": "idx_message_request_created_at_id_active",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_model_active": {
-          "name": "idx_message_request_model_active",
-          "columns": [
-            {
-              "expression": "model",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"model\" IS NOT NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_status_code_active": {
-          "name": "idx_message_request_status_code_active",
-          "columns": [
-            {
-              "expression": "status_code",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"status_code\" IS NOT NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_created_at": {
-          "name": "idx_message_request_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_deleted_at": {
-          "name": "idx_message_request_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.model_prices": {
-      "name": "model_prices",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "model_name": {
-          "name": "model_name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "price_data": {
-          "name": "price_data",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "source": {
-          "name": "source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'litellm'"
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_model_prices_latest": {
-          "name": "idx_model_prices_latest",
-          "columns": [
-            {
-              "expression": "model_name",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_model_name": {
-          "name": "idx_model_prices_model_name",
-          "columns": [
-            {
-              "expression": "model_name",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_created_at": {
-          "name": "idx_model_prices_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_source": {
-          "name": "idx_model_prices_source",
-          "columns": [
-            {
-              "expression": "source",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.notification_settings": {
-      "name": "notification_settings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "enabled": {
-          "name": "enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "use_legacy_mode": {
-          "name": "use_legacy_mode",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "circuit_breaker_enabled": {
-          "name": "circuit_breaker_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "circuit_breaker_webhook": {
-          "name": "circuit_breaker_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_leaderboard_enabled": {
-          "name": "daily_leaderboard_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "daily_leaderboard_webhook": {
-          "name": "daily_leaderboard_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_leaderboard_time": {
-          "name": "daily_leaderboard_time",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'09:00'"
-        },
-        "daily_leaderboard_top_n": {
-          "name": "daily_leaderboard_top_n",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 5
-        },
-        "cost_alert_enabled": {
-          "name": "cost_alert_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "cost_alert_webhook": {
-          "name": "cost_alert_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cost_alert_threshold": {
-          "name": "cost_alert_threshold",
-          "type": "numeric(5, 2)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.80'"
-        },
-        "cost_alert_check_interval": {
-          "name": "cost_alert_check_interval",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 60
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.notification_target_bindings": {
-      "name": "notification_target_bindings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "notification_type": {
-          "name": "notification_type",
-          "type": "notification_type",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "target_id": {
-          "name": "target_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "schedule_cron": {
-          "name": "schedule_cron",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "schedule_timezone": {
-          "name": "schedule_timezone",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "template_override": {
-          "name": "template_override",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "unique_notification_target_binding": {
-          "name": "unique_notification_target_binding",
-          "columns": [
-            {
-              "expression": "notification_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "target_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_notification_bindings_type": {
-          "name": "idx_notification_bindings_type",
-          "columns": [
-            {
-              "expression": "notification_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_notification_bindings_target": {
-          "name": "idx_notification_bindings_target",
-          "columns": [
-            {
-              "expression": "target_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "notification_target_bindings_target_id_webhook_targets_id_fk": {
-          "name": "notification_target_bindings_target_id_webhook_targets_id_fk",
-          "tableFrom": "notification_target_bindings",
-          "tableTo": "webhook_targets",
-          "columnsFrom": [
-            "target_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_endpoint_probe_logs": {
-      "name": "provider_endpoint_probe_logs",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "endpoint_id": {
-          "name": "endpoint_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "source": {
-          "name": "source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'scheduled'"
-        },
-        "ok": {
-          "name": "ok",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "status_code": {
-          "name": "status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "latency_ms": {
-          "name": "latency_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_type": {
-          "name": "error_type",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_message": {
-          "name": "error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_provider_endpoint_probe_logs_endpoint_created_at": {
-          "name": "idx_provider_endpoint_probe_logs_endpoint_created_at",
-          "columns": [
-            {
-              "expression": "endpoint_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoint_probe_logs_created_at": {
-          "name": "idx_provider_endpoint_probe_logs_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "provider_endpoint_probe_logs_endpoint_id_provider_endpoints_id_fk": {
-          "name": "provider_endpoint_probe_logs_endpoint_id_provider_endpoints_id_fk",
-          "tableFrom": "provider_endpoint_probe_logs",
-          "tableTo": "provider_endpoints",
-          "columnsFrom": [
-            "endpoint_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_endpoints": {
-      "name": "provider_endpoints",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "vendor_id": {
-          "name": "vendor_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'claude'"
-        },
-        "url": {
-          "name": "url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "label": {
-          "name": "label",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "sort_order": {
-          "name": "sort_order",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "last_probed_at": {
-          "name": "last_probed_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_ok": {
-          "name": "last_probe_ok",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_status_code": {
-          "name": "last_probe_status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_latency_ms": {
-          "name": "last_probe_latency_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_error_type": {
-          "name": "last_probe_error_type",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_error_message": {
-          "name": "last_probe_error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "uniq_provider_endpoints_vendor_type_url": {
-          "name": "uniq_provider_endpoints_vendor_type_url",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_vendor_type": {
-          "name": "idx_provider_endpoints_vendor_type",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_enabled": {
-          "name": "idx_provider_endpoints_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_pick_enabled": {
-          "name": "idx_provider_endpoints_pick_enabled",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "sort_order",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_created_at": {
-          "name": "idx_provider_endpoints_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_deleted_at": {
-          "name": "idx_provider_endpoints_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "provider_endpoints_vendor_id_provider_vendors_id_fk": {
-          "name": "provider_endpoints_vendor_id_provider_vendors_id_fk",
-          "tableFrom": "provider_endpoints",
-          "tableTo": "provider_vendors",
-          "columnsFrom": [
-            "vendor_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_vendors": {
-      "name": "provider_vendors",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "website_domain": {
-          "name": "website_domain",
-          "type": "varchar(255)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "display_name": {
-          "name": "display_name",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "website_url": {
-          "name": "website_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "favicon_url": {
-          "name": "favicon_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "uniq_provider_vendors_website_domain": {
-          "name": "uniq_provider_vendors_website_domain",
-          "columns": [
-            {
-              "expression": "website_domain",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_vendors_created_at": {
-          "name": "idx_provider_vendors_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.providers": {
-      "name": "providers",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "url": {
-          "name": "url",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_vendor_id": {
-          "name": "provider_vendor_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "weight": {
-          "name": "weight",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 1
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "group_priorities": {
-          "name": "group_priorities",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "cost_multiplier": {
-          "name": "cost_multiplier",
-          "type": "numeric(10, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'1.0'"
-        },
-        "group_tag": {
-          "name": "group_tag",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'claude'"
-        },
-        "preserve_client_ip": {
-          "name": "preserve_client_ip",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "model_redirects": {
-          "name": "model_redirects",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "allowed_models": {
-          "name": "allowed_models",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "join_claude_pool": {
-          "name": "join_claude_pool",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "codex_instructions_strategy": {
-          "name": "codex_instructions_strategy",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'auto'"
-        },
-        "mcp_passthrough_type": {
-          "name": "mcp_passthrough_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'none'"
-        },
-        "mcp_passthrough_url": {
-          "name": "mcp_passthrough_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_daily_usd": {
-          "name": "limit_daily_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "total_cost_reset_at": {
-          "name": "total_cost_reset_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "max_retry_attempts": {
-          "name": "max_retry_attempts",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "circuit_breaker_failure_threshold": {
-          "name": "circuit_breaker_failure_threshold",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 5
-        },
-        "circuit_breaker_open_duration": {
-          "name": "circuit_breaker_open_duration",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 1800000
-        },
-        "circuit_breaker_half_open_success_threshold": {
-          "name": "circuit_breaker_half_open_success_threshold",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 2
-        },
-        "proxy_url": {
-          "name": "proxy_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_fallback_to_direct": {
-          "name": "proxy_fallback_to_direct",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "first_byte_timeout_streaming_ms": {
-          "name": "first_byte_timeout_streaming_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "streaming_idle_timeout_ms": {
-          "name": "streaming_idle_timeout_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "request_timeout_non_streaming_ms": {
-          "name": "request_timeout_non_streaming_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "website_url": {
-          "name": "website_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "favicon_url": {
-          "name": "favicon_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_ttl_preference": {
-          "name": "cache_ttl_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "context_1m_preference": {
-          "name": "context_1m_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_reasoning_effort_preference": {
-          "name": "codex_reasoning_effort_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_reasoning_summary_preference": {
-          "name": "codex_reasoning_summary_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_text_verbosity_preference": {
-          "name": "codex_text_verbosity_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_parallel_tool_calls_preference": {
-          "name": "codex_parallel_tool_calls_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_max_tokens_preference": {
-          "name": "anthropic_max_tokens_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_thinking_budget_preference": {
-          "name": "anthropic_thinking_budget_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_adaptive_thinking": {
-          "name": "anthropic_adaptive_thinking",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "gemini_google_search_preference": {
-          "name": "gemini_google_search_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "tpm": {
-          "name": "tpm",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "rpm": {
-          "name": "rpm",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "rpd": {
-          "name": "rpd",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "cc": {
-          "name": "cc",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_providers_enabled_priority": {
-          "name": "idx_providers_enabled_priority",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "weight",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_group": {
-          "name": "idx_providers_group",
-          "columns": [
-            {
-              "expression": "group_tag",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_vendor_type_url_active": {
-          "name": "idx_providers_vendor_type_url_active",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_created_at": {
-          "name": "idx_providers_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_deleted_at": {
-          "name": "idx_providers_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_vendor_type": {
-          "name": "idx_providers_vendor_type",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "providers_provider_vendor_id_provider_vendors_id_fk": {
-          "name": "providers_provider_vendor_id_provider_vendors_id_fk",
-          "tableFrom": "providers",
-          "tableTo": "provider_vendors",
-          "columnsFrom": [
-            "provider_vendor_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "restrict",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.request_filters": {
-      "name": "request_filters",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "scope": {
-          "name": "scope",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "action": {
-          "name": "action",
-          "type": "varchar(30)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "target": {
-          "name": "target",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "replacement": {
-          "name": "replacement",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "binding_type": {
-          "name": "binding_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'global'"
-        },
-        "provider_ids": {
-          "name": "provider_ids",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "group_tags": {
-          "name": "group_tags",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_request_filters_enabled": {
-          "name": "idx_request_filters_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_scope": {
-          "name": "idx_request_filters_scope",
-          "columns": [
-            {
-              "expression": "scope",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_action": {
-          "name": "idx_request_filters_action",
-          "columns": [
-            {
-              "expression": "action",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_binding": {
-          "name": "idx_request_filters_binding",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "binding_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.sensitive_words": {
-      "name": "sensitive_words",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "word": {
-          "name": "word",
-          "type": "varchar(255)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'contains'"
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_sensitive_words_enabled": {
-          "name": "idx_sensitive_words_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "match_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_sensitive_words_created_at": {
-          "name": "idx_sensitive_words_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.system_settings": {
-      "name": "system_settings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "site_title": {
-          "name": "site_title",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'Claude Code Hub'"
-        },
-        "allow_global_usage_view": {
-          "name": "allow_global_usage_view",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "currency_display": {
-          "name": "currency_display",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'USD'"
-        },
-        "billing_model_source": {
-          "name": "billing_model_source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'original'"
-        },
-        "timezone": {
-          "name": "timezone",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "enable_auto_cleanup": {
-          "name": "enable_auto_cleanup",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "cleanup_retention_days": {
-          "name": "cleanup_retention_days",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 30
-        },
-        "cleanup_schedule": {
-          "name": "cleanup_schedule",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0 2 * * *'"
-        },
-        "cleanup_batch_size": {
-          "name": "cleanup_batch_size",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 10000
-        },
-        "enable_client_version_check": {
-          "name": "enable_client_version_check",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "verbose_provider_error": {
-          "name": "verbose_provider_error",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "enable_http2": {
-          "name": "enable_http2",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "intercept_anthropic_warmup_requests": {
-          "name": "intercept_anthropic_warmup_requests",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "enable_thinking_signature_rectifier": {
-          "name": "enable_thinking_signature_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_thinking_budget_rectifier": {
-          "name": "enable_thinking_budget_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_billing_header_rectifier": {
-          "name": "enable_billing_header_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_codex_session_id_completion": {
-          "name": "enable_codex_session_id_completion",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_claude_metadata_user_id_injection": {
-          "name": "enable_claude_metadata_user_id_injection",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_response_fixer": {
-          "name": "enable_response_fixer",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "response_fixer_config": {
-          "name": "response_fixer_config",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'{\"fixTruncatedJson\":true,\"fixSseFormat\":true,\"fixEncoding\":true,\"maxJsonDepth\":200,\"maxFixSize\":1048576}'::jsonb"
-        },
-        "quota_db_refresh_interval_seconds": {
-          "name": "quota_db_refresh_interval_seconds",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 10
-        },
-        "quota_lease_percent_5h": {
-          "name": "quota_lease_percent_5h",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_daily": {
-          "name": "quota_lease_percent_daily",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_weekly": {
-          "name": "quota_lease_percent_weekly",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_monthly": {
-          "name": "quota_lease_percent_monthly",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_cap_usd": {
-          "name": "quota_lease_cap_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.users": {
-      "name": "users",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "role": {
-          "name": "role",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'user'"
-        },
-        "rpm_limit": {
-          "name": "rpm_limit",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_limit_usd": {
-          "name": "daily_limit_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "provider_group": {
-          "name": "provider_group",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'default'"
-        },
-        "tags": {
-          "name": "tags",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "expires_at": {
-          "name": "expires_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "allowed_clients": {
-          "name": "allowed_clients",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "allowed_models": {
-          "name": "allowed_models",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_users_active_role_sort": {
-          "name": "idx_users_active_role_sort",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "role",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_enabled_expires_at": {
-          "name": "idx_users_enabled_expires_at",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "expires_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_tags_gin": {
-          "name": "idx_users_tags_gin",
-          "columns": [
-            {
-              "expression": "tags",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "gin",
-          "with": {}
-        },
-        "idx_users_created_at": {
-          "name": "idx_users_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_deleted_at": {
-          "name": "idx_users_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.webhook_targets": {
-      "name": "webhook_targets",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "webhook_provider_type",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "webhook_url": {
-          "name": "webhook_url",
-          "type": "varchar(1024)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "telegram_bot_token": {
-          "name": "telegram_bot_token",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "telegram_chat_id": {
-          "name": "telegram_chat_id",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "dingtalk_secret": {
-          "name": "dingtalk_secret",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "custom_template": {
-          "name": "custom_template",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "custom_headers": {
-          "name": "custom_headers",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_url": {
-          "name": "proxy_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_fallback_to_direct": {
-          "name": "proxy_fallback_to_direct",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "last_test_at": {
-          "name": "last_test_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_test_result": {
-          "name": "last_test_result",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    }
-  },
-  "enums": {
-    "public.daily_reset_mode": {
-      "name": "daily_reset_mode",
-      "schema": "public",
-      "values": [
-        "fixed",
-        "rolling"
-      ]
-    },
-    "public.notification_type": {
-      "name": "notification_type",
-      "schema": "public",
-      "values": [
-        "circuit_breaker",
-        "daily_leaderboard",
-        "cost_alert"
-      ]
-    },
-    "public.webhook_provider_type": {
-      "name": "webhook_provider_type",
-      "schema": "public",
-      "values": [
-        "wechat",
-        "feishu",
-        "dingtalk",
-        "telegram",
-        "custom"
-      ]
-    }
-  },
-  "schemas": {},
-  "sequences": {},
-  "roles": {},
-  "policies": {},
-  "views": {},
-  "_meta": {
-    "columns": {},
-    "schemas": {},
-    "tables": {}
-  }
-}

+ 0 - 3237
drizzle/meta/0073_snapshot.json

@@ -1,3237 +0,0 @@
-{
-  "id": "f72efbe3-232d-4af3-aa00-f0e8f7099bdf",
-  "prevId": "f9f36628-8ee9-464a-94da-8d6ef636ebdb",
-  "version": "7",
-  "dialect": "postgresql",
-  "tables": {
-    "public.error_rules": {
-      "name": "error_rules",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "pattern": {
-          "name": "pattern",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'regex'"
-        },
-        "category": {
-          "name": "category",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "override_response": {
-          "name": "override_response",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "override_status_code": {
-          "name": "override_status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "is_default": {
-          "name": "is_default",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_error_rules_enabled": {
-          "name": "idx_error_rules_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "unique_pattern": {
-          "name": "unique_pattern",
-          "columns": [
-            {
-              "expression": "pattern",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_category": {
-          "name": "idx_category",
-          "columns": [
-            {
-              "expression": "category",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_match_type": {
-          "name": "idx_match_type",
-          "columns": [
-            {
-              "expression": "match_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.keys": {
-      "name": "keys",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "user_id": {
-          "name": "user_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": true
-        },
-        "expires_at": {
-          "name": "expires_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "can_login_web_ui": {
-          "name": "can_login_web_ui",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_daily_usd": {
-          "name": "limit_daily_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "provider_group": {
-          "name": "provider_group",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'default'"
-        },
-        "cache_ttl_preference": {
-          "name": "cache_ttl_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_keys_user_id": {
-          "name": "idx_keys_user_id",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_key": {
-          "name": "idx_keys_key",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_created_at": {
-          "name": "idx_keys_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_keys_deleted_at": {
-          "name": "idx_keys_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.message_request": {
-      "name": "message_request",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "provider_id": {
-          "name": "provider_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "user_id": {
-          "name": "user_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "model": {
-          "name": "model",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "duration_ms": {
-          "name": "duration_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cost_usd": {
-          "name": "cost_usd",
-          "type": "numeric(21, 15)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0'"
-        },
-        "cost_multiplier": {
-          "name": "cost_multiplier",
-          "type": "numeric(10, 4)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "session_id": {
-          "name": "session_id",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "request_sequence": {
-          "name": "request_sequence",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 1
-        },
-        "provider_chain": {
-          "name": "provider_chain",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "status_code": {
-          "name": "status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "api_type": {
-          "name": "api_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "endpoint": {
-          "name": "endpoint",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "original_model": {
-          "name": "original_model",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "input_tokens": {
-          "name": "input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "output_tokens": {
-          "name": "output_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "ttfb_ms": {
-          "name": "ttfb_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_input_tokens": {
-          "name": "cache_creation_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_read_input_tokens": {
-          "name": "cache_read_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_5m_input_tokens": {
-          "name": "cache_creation_5m_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_creation_1h_input_tokens": {
-          "name": "cache_creation_1h_input_tokens",
-          "type": "bigint",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_ttl_applied": {
-          "name": "cache_ttl_applied",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "context_1m_applied": {
-          "name": "context_1m_applied",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "special_settings": {
-          "name": "special_settings",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_message": {
-          "name": "error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_stack": {
-          "name": "error_stack",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_cause": {
-          "name": "error_cause",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "blocked_by": {
-          "name": "blocked_by",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "blocked_reason": {
-          "name": "blocked_reason",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "user_agent": {
-          "name": "user_agent",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "messages_count": {
-          "name": "messages_count",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_message_request_user_date_cost": {
-          "name": "idx_message_request_user_date_cost",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "cost_usd",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_user_query": {
-          "name": "idx_message_request_user_query",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_id": {
-          "name": "idx_message_request_session_id",
-          "columns": [
-            {
-              "expression": "session_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_id_prefix": {
-          "name": "idx_message_request_session_id_prefix",
-          "columns": [
-            {
-              "expression": "\"session_id\" varchar_pattern_ops",
-              "asc": true,
-              "isExpression": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_session_seq": {
-          "name": "idx_message_request_session_seq",
-          "columns": [
-            {
-              "expression": "session_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "request_sequence",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_endpoint": {
-          "name": "idx_message_request_endpoint",
-          "columns": [
-            {
-              "expression": "endpoint",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_blocked_by": {
-          "name": "idx_message_request_blocked_by",
-          "columns": [
-            {
-              "expression": "blocked_by",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_provider_id": {
-          "name": "idx_message_request_provider_id",
-          "columns": [
-            {
-              "expression": "provider_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_user_id": {
-          "name": "idx_message_request_user_id",
-          "columns": [
-            {
-              "expression": "user_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key": {
-          "name": "idx_message_request_key",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key_created_at_id": {
-          "name": "idx_message_request_key_created_at_id",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key_model_active": {
-          "name": "idx_message_request_key_model_active",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "model",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"model\" IS NOT NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_key_endpoint_active": {
-          "name": "idx_message_request_key_endpoint_active",
-          "columns": [
-            {
-              "expression": "key",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "endpoint",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"endpoint\" IS NOT NULL AND (\"message_request\".\"blocked_by\" IS NULL OR \"message_request\".\"blocked_by\" <> 'warmup')",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_created_at_id_active": {
-          "name": "idx_message_request_created_at_id_active",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_model_active": {
-          "name": "idx_message_request_model_active",
-          "columns": [
-            {
-              "expression": "model",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"model\" IS NOT NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_status_code_active": {
-          "name": "idx_message_request_status_code_active",
-          "columns": [
-            {
-              "expression": "status_code",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"message_request\".\"deleted_at\" IS NULL AND \"message_request\".\"status_code\" IS NOT NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_created_at": {
-          "name": "idx_message_request_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_message_request_deleted_at": {
-          "name": "idx_message_request_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.model_prices": {
-      "name": "model_prices",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "model_name": {
-          "name": "model_name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "price_data": {
-          "name": "price_data",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "source": {
-          "name": "source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'litellm'"
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_model_prices_latest": {
-          "name": "idx_model_prices_latest",
-          "columns": [
-            {
-              "expression": "model_name",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_model_name": {
-          "name": "idx_model_prices_model_name",
-          "columns": [
-            {
-              "expression": "model_name",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_created_at": {
-          "name": "idx_model_prices_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_model_prices_source": {
-          "name": "idx_model_prices_source",
-          "columns": [
-            {
-              "expression": "source",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.notification_settings": {
-      "name": "notification_settings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "enabled": {
-          "name": "enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "use_legacy_mode": {
-          "name": "use_legacy_mode",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "circuit_breaker_enabled": {
-          "name": "circuit_breaker_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "circuit_breaker_webhook": {
-          "name": "circuit_breaker_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_leaderboard_enabled": {
-          "name": "daily_leaderboard_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "daily_leaderboard_webhook": {
-          "name": "daily_leaderboard_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_leaderboard_time": {
-          "name": "daily_leaderboard_time",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'09:00'"
-        },
-        "daily_leaderboard_top_n": {
-          "name": "daily_leaderboard_top_n",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 5
-        },
-        "cost_alert_enabled": {
-          "name": "cost_alert_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "cost_alert_webhook": {
-          "name": "cost_alert_webhook",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cost_alert_threshold": {
-          "name": "cost_alert_threshold",
-          "type": "numeric(5, 2)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.80'"
-        },
-        "cost_alert_check_interval": {
-          "name": "cost_alert_check_interval",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 60
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.notification_target_bindings": {
-      "name": "notification_target_bindings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "notification_type": {
-          "name": "notification_type",
-          "type": "notification_type",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "target_id": {
-          "name": "target_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "schedule_cron": {
-          "name": "schedule_cron",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "schedule_timezone": {
-          "name": "schedule_timezone",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "template_override": {
-          "name": "template_override",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "unique_notification_target_binding": {
-          "name": "unique_notification_target_binding",
-          "columns": [
-            {
-              "expression": "notification_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "target_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_notification_bindings_type": {
-          "name": "idx_notification_bindings_type",
-          "columns": [
-            {
-              "expression": "notification_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_notification_bindings_target": {
-          "name": "idx_notification_bindings_target",
-          "columns": [
-            {
-              "expression": "target_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "notification_target_bindings_target_id_webhook_targets_id_fk": {
-          "name": "notification_target_bindings_target_id_webhook_targets_id_fk",
-          "tableFrom": "notification_target_bindings",
-          "tableTo": "webhook_targets",
-          "columnsFrom": [
-            "target_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_endpoint_probe_logs": {
-      "name": "provider_endpoint_probe_logs",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "endpoint_id": {
-          "name": "endpoint_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "source": {
-          "name": "source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'scheduled'"
-        },
-        "ok": {
-          "name": "ok",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "status_code": {
-          "name": "status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "latency_ms": {
-          "name": "latency_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_type": {
-          "name": "error_type",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "error_message": {
-          "name": "error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_provider_endpoint_probe_logs_endpoint_created_at": {
-          "name": "idx_provider_endpoint_probe_logs_endpoint_created_at",
-          "columns": [
-            {
-              "expression": "endpoint_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": false,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoint_probe_logs_created_at": {
-          "name": "idx_provider_endpoint_probe_logs_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "provider_endpoint_probe_logs_endpoint_id_provider_endpoints_id_fk": {
-          "name": "provider_endpoint_probe_logs_endpoint_id_provider_endpoints_id_fk",
-          "tableFrom": "provider_endpoint_probe_logs",
-          "tableTo": "provider_endpoints",
-          "columnsFrom": [
-            "endpoint_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_endpoints": {
-      "name": "provider_endpoints",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "vendor_id": {
-          "name": "vendor_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'claude'"
-        },
-        "url": {
-          "name": "url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "label": {
-          "name": "label",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "sort_order": {
-          "name": "sort_order",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "last_probed_at": {
-          "name": "last_probed_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_ok": {
-          "name": "last_probe_ok",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_status_code": {
-          "name": "last_probe_status_code",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_latency_ms": {
-          "name": "last_probe_latency_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_error_type": {
-          "name": "last_probe_error_type",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_probe_error_message": {
-          "name": "last_probe_error_message",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "uniq_provider_endpoints_vendor_type_url": {
-          "name": "uniq_provider_endpoints_vendor_type_url",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_vendor_type": {
-          "name": "idx_provider_endpoints_vendor_type",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_enabled": {
-          "name": "idx_provider_endpoints_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_pick_enabled": {
-          "name": "idx_provider_endpoints_pick_enabled",
-          "columns": [
-            {
-              "expression": "vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "sort_order",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"provider_endpoints\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_created_at": {
-          "name": "idx_provider_endpoints_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_endpoints_deleted_at": {
-          "name": "idx_provider_endpoints_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "provider_endpoints_vendor_id_provider_vendors_id_fk": {
-          "name": "provider_endpoints_vendor_id_provider_vendors_id_fk",
-          "tableFrom": "provider_endpoints",
-          "tableTo": "provider_vendors",
-          "columnsFrom": [
-            "vendor_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "cascade",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.provider_vendors": {
-      "name": "provider_vendors",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "website_domain": {
-          "name": "website_domain",
-          "type": "varchar(255)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "display_name": {
-          "name": "display_name",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "website_url": {
-          "name": "website_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "favicon_url": {
-          "name": "favicon_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "uniq_provider_vendors_website_domain": {
-          "name": "uniq_provider_vendors_website_domain",
-          "columns": [
-            {
-              "expression": "website_domain",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": true,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_provider_vendors_created_at": {
-          "name": "idx_provider_vendors_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.providers": {
-      "name": "providers",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "url": {
-          "name": "url",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "key": {
-          "name": "key",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_vendor_id": {
-          "name": "provider_vendor_id",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "weight": {
-          "name": "weight",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 1
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "group_priorities": {
-          "name": "group_priorities",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "cost_multiplier": {
-          "name": "cost_multiplier",
-          "type": "numeric(10, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'1.0'"
-        },
-        "group_tag": {
-          "name": "group_tag",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'claude'"
-        },
-        "preserve_client_ip": {
-          "name": "preserve_client_ip",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "model_redirects": {
-          "name": "model_redirects",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "allowed_models": {
-          "name": "allowed_models",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "join_claude_pool": {
-          "name": "join_claude_pool",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "codex_instructions_strategy": {
-          "name": "codex_instructions_strategy",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'auto'"
-        },
-        "mcp_passthrough_type": {
-          "name": "mcp_passthrough_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'none'"
-        },
-        "mcp_passthrough_url": {
-          "name": "mcp_passthrough_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_daily_usd": {
-          "name": "limit_daily_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "total_cost_reset_at": {
-          "name": "total_cost_reset_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "max_retry_attempts": {
-          "name": "max_retry_attempts",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "circuit_breaker_failure_threshold": {
-          "name": "circuit_breaker_failure_threshold",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 5
-        },
-        "circuit_breaker_open_duration": {
-          "name": "circuit_breaker_open_duration",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 1800000
-        },
-        "circuit_breaker_half_open_success_threshold": {
-          "name": "circuit_breaker_half_open_success_threshold",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 2
-        },
-        "proxy_url": {
-          "name": "proxy_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_fallback_to_direct": {
-          "name": "proxy_fallback_to_direct",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "first_byte_timeout_streaming_ms": {
-          "name": "first_byte_timeout_streaming_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "streaming_idle_timeout_ms": {
-          "name": "streaming_idle_timeout_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "request_timeout_non_streaming_ms": {
-          "name": "request_timeout_non_streaming_ms",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "website_url": {
-          "name": "website_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "favicon_url": {
-          "name": "favicon_url",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "cache_ttl_preference": {
-          "name": "cache_ttl_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "context_1m_preference": {
-          "name": "context_1m_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_reasoning_effort_preference": {
-          "name": "codex_reasoning_effort_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_reasoning_summary_preference": {
-          "name": "codex_reasoning_summary_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_text_verbosity_preference": {
-          "name": "codex_text_verbosity_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "codex_parallel_tool_calls_preference": {
-          "name": "codex_parallel_tool_calls_preference",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_max_tokens_preference": {
-          "name": "anthropic_max_tokens_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_thinking_budget_preference": {
-          "name": "anthropic_thinking_budget_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "anthropic_adaptive_thinking": {
-          "name": "anthropic_adaptive_thinking",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'null'::jsonb"
-        },
-        "gemini_google_search_preference": {
-          "name": "gemini_google_search_preference",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "tpm": {
-          "name": "tpm",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "rpm": {
-          "name": "rpm",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "rpd": {
-          "name": "rpd",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "cc": {
-          "name": "cc",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 0
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_providers_enabled_priority": {
-          "name": "idx_providers_enabled_priority",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "weight",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_group": {
-          "name": "idx_providers_group",
-          "columns": [
-            {
-              "expression": "group_tag",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_vendor_type_url_active": {
-          "name": "idx_providers_vendor_type_url_active",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "url",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_created_at": {
-          "name": "idx_providers_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_deleted_at": {
-          "name": "idx_providers_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_vendor_type": {
-          "name": "idx_providers_vendor_type",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_providers_enabled_vendor_type": {
-          "name": "idx_providers_enabled_vendor_type",
-          "columns": [
-            {
-              "expression": "provider_vendor_id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "provider_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"providers\".\"deleted_at\" IS NULL AND \"providers\".\"is_enabled\" = true AND \"providers\".\"provider_vendor_id\" IS NOT NULL AND \"providers\".\"provider_vendor_id\" > 0",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {
-        "providers_provider_vendor_id_provider_vendors_id_fk": {
-          "name": "providers_provider_vendor_id_provider_vendors_id_fk",
-          "tableFrom": "providers",
-          "tableTo": "provider_vendors",
-          "columnsFrom": [
-            "provider_vendor_id"
-          ],
-          "columnsTo": [
-            "id"
-          ],
-          "onDelete": "restrict",
-          "onUpdate": "no action"
-        }
-      },
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.request_filters": {
-      "name": "request_filters",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "scope": {
-          "name": "scope",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "action": {
-          "name": "action",
-          "type": "varchar(30)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "target": {
-          "name": "target",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "replacement": {
-          "name": "replacement",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "priority": {
-          "name": "priority",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": true,
-          "default": 0
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "binding_type": {
-          "name": "binding_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'global'"
-        },
-        "provider_ids": {
-          "name": "provider_ids",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "group_tags": {
-          "name": "group_tags",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_request_filters_enabled": {
-          "name": "idx_request_filters_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "priority",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_scope": {
-          "name": "idx_request_filters_scope",
-          "columns": [
-            {
-              "expression": "scope",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_action": {
-          "name": "idx_request_filters_action",
-          "columns": [
-            {
-              "expression": "action",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_request_filters_binding": {
-          "name": "idx_request_filters_binding",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "binding_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.sensitive_words": {
-      "name": "sensitive_words",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "word": {
-          "name": "word",
-          "type": "varchar(255)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "match_type": {
-          "name": "match_type",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'contains'"
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {
-        "idx_sensitive_words_enabled": {
-          "name": "idx_sensitive_words_enabled",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "match_type",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_sensitive_words_created_at": {
-          "name": "idx_sensitive_words_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.system_settings": {
-      "name": "system_settings",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "site_title": {
-          "name": "site_title",
-          "type": "varchar(128)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'Claude Code Hub'"
-        },
-        "allow_global_usage_view": {
-          "name": "allow_global_usage_view",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "currency_display": {
-          "name": "currency_display",
-          "type": "varchar(10)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'USD'"
-        },
-        "billing_model_source": {
-          "name": "billing_model_source",
-          "type": "varchar(20)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'original'"
-        },
-        "timezone": {
-          "name": "timezone",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "enable_auto_cleanup": {
-          "name": "enable_auto_cleanup",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "cleanup_retention_days": {
-          "name": "cleanup_retention_days",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 30
-        },
-        "cleanup_schedule": {
-          "name": "cleanup_schedule",
-          "type": "varchar(50)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0 2 * * *'"
-        },
-        "cleanup_batch_size": {
-          "name": "cleanup_batch_size",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 10000
-        },
-        "enable_client_version_check": {
-          "name": "enable_client_version_check",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "verbose_provider_error": {
-          "name": "verbose_provider_error",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "enable_http2": {
-          "name": "enable_http2",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "intercept_anthropic_warmup_requests": {
-          "name": "intercept_anthropic_warmup_requests",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": false
-        },
-        "enable_thinking_signature_rectifier": {
-          "name": "enable_thinking_signature_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_thinking_budget_rectifier": {
-          "name": "enable_thinking_budget_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_billing_header_rectifier": {
-          "name": "enable_billing_header_rectifier",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_codex_session_id_completion": {
-          "name": "enable_codex_session_id_completion",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_claude_metadata_user_id_injection": {
-          "name": "enable_claude_metadata_user_id_injection",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "enable_response_fixer": {
-          "name": "enable_response_fixer",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "response_fixer_config": {
-          "name": "response_fixer_config",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'{\"fixTruncatedJson\":true,\"fixSseFormat\":true,\"fixEncoding\":true,\"maxJsonDepth\":200,\"maxFixSize\":1048576}'::jsonb"
-        },
-        "quota_db_refresh_interval_seconds": {
-          "name": "quota_db_refresh_interval_seconds",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false,
-          "default": 10
-        },
-        "quota_lease_percent_5h": {
-          "name": "quota_lease_percent_5h",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_daily": {
-          "name": "quota_lease_percent_daily",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_weekly": {
-          "name": "quota_lease_percent_weekly",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_percent_monthly": {
-          "name": "quota_lease_percent_monthly",
-          "type": "numeric(5, 4)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'0.05'"
-        },
-        "quota_lease_cap_usd": {
-          "name": "quota_lease_cap_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.users": {
-      "name": "users",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "description": {
-          "name": "description",
-          "type": "text",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "role": {
-          "name": "role",
-          "type": "varchar",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'user'"
-        },
-        "rpm_limit": {
-          "name": "rpm_limit",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_limit_usd": {
-          "name": "daily_limit_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "provider_group": {
-          "name": "provider_group",
-          "type": "varchar(200)",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'default'"
-        },
-        "tags": {
-          "name": "tags",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "limit_5h_usd": {
-          "name": "limit_5h_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_weekly_usd": {
-          "name": "limit_weekly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_monthly_usd": {
-          "name": "limit_monthly_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_total_usd": {
-          "name": "limit_total_usd",
-          "type": "numeric(10, 2)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "limit_concurrent_sessions": {
-          "name": "limit_concurrent_sessions",
-          "type": "integer",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "daily_reset_mode": {
-          "name": "daily_reset_mode",
-          "type": "daily_reset_mode",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'fixed'"
-        },
-        "daily_reset_time": {
-          "name": "daily_reset_time",
-          "type": "varchar(5)",
-          "primaryKey": false,
-          "notNull": true,
-          "default": "'00:00'"
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "expires_at": {
-          "name": "expires_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "allowed_clients": {
-          "name": "allowed_clients",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "allowed_models": {
-          "name": "allowed_models",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "'[]'::jsonb"
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "deleted_at": {
-          "name": "deleted_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        }
-      },
-      "indexes": {
-        "idx_users_active_role_sort": {
-          "name": "idx_users_active_role_sort",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "role",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "id",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_enabled_expires_at": {
-          "name": "idx_users_enabled_expires_at",
-          "columns": [
-            {
-              "expression": "is_enabled",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            },
-            {
-              "expression": "expires_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_tags_gin": {
-          "name": "idx_users_tags_gin",
-          "columns": [
-            {
-              "expression": "tags",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "where": "\"users\".\"deleted_at\" IS NULL",
-          "concurrently": false,
-          "method": "gin",
-          "with": {}
-        },
-        "idx_users_created_at": {
-          "name": "idx_users_created_at",
-          "columns": [
-            {
-              "expression": "created_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        },
-        "idx_users_deleted_at": {
-          "name": "idx_users_deleted_at",
-          "columns": [
-            {
-              "expression": "deleted_at",
-              "isExpression": false,
-              "asc": true,
-              "nulls": "last"
-            }
-          ],
-          "isUnique": false,
-          "concurrently": false,
-          "method": "btree",
-          "with": {}
-        }
-      },
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    },
-    "public.webhook_targets": {
-      "name": "webhook_targets",
-      "schema": "",
-      "columns": {
-        "id": {
-          "name": "id",
-          "type": "serial",
-          "primaryKey": true,
-          "notNull": true
-        },
-        "name": {
-          "name": "name",
-          "type": "varchar(100)",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "provider_type": {
-          "name": "provider_type",
-          "type": "webhook_provider_type",
-          "typeSchema": "public",
-          "primaryKey": false,
-          "notNull": true
-        },
-        "webhook_url": {
-          "name": "webhook_url",
-          "type": "varchar(1024)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "telegram_bot_token": {
-          "name": "telegram_bot_token",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "telegram_chat_id": {
-          "name": "telegram_chat_id",
-          "type": "varchar(64)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "dingtalk_secret": {
-          "name": "dingtalk_secret",
-          "type": "varchar(256)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "custom_template": {
-          "name": "custom_template",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "custom_headers": {
-          "name": "custom_headers",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_url": {
-          "name": "proxy_url",
-          "type": "varchar(512)",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "proxy_fallback_to_direct": {
-          "name": "proxy_fallback_to_direct",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": false,
-          "default": false
-        },
-        "is_enabled": {
-          "name": "is_enabled",
-          "type": "boolean",
-          "primaryKey": false,
-          "notNull": true,
-          "default": true
-        },
-        "last_test_at": {
-          "name": "last_test_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "last_test_result": {
-          "name": "last_test_result",
-          "type": "jsonb",
-          "primaryKey": false,
-          "notNull": false
-        },
-        "created_at": {
-          "name": "created_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        },
-        "updated_at": {
-          "name": "updated_at",
-          "type": "timestamp with time zone",
-          "primaryKey": false,
-          "notNull": false,
-          "default": "now()"
-        }
-      },
-      "indexes": {},
-      "foreignKeys": {},
-      "compositePrimaryKeys": {},
-      "uniqueConstraints": {},
-      "policies": {},
-      "checkConstraints": {},
-      "isRLSEnabled": false
-    }
-  },
-  "enums": {
-    "public.daily_reset_mode": {
-      "name": "daily_reset_mode",
-      "schema": "public",
-      "values": [
-        "fixed",
-        "rolling"
-      ]
-    },
-    "public.notification_type": {
-      "name": "notification_type",
-      "schema": "public",
-      "values": [
-        "circuit_breaker",
-        "daily_leaderboard",
-        "cost_alert"
-      ]
-    },
-    "public.webhook_provider_type": {
-      "name": "webhook_provider_type",
-      "schema": "public",
-      "values": [
-        "wechat",
-        "feishu",
-        "dingtalk",
-        "telegram",
-        "custom"
-      ]
-    }
-  },
-  "schemas": {},
-  "sequences": {},
-  "roles": {},
-  "policies": {},
-  "views": {},
-  "_meta": {
-    "columns": {},
-    "schemas": {},
-    "tables": {}
-  }
-}

+ 2 - 37
drizzle/meta/_journal.json

@@ -481,43 +481,8 @@
     {
       "idx": 68,
       "version": "7",
-      "when": 1771062933911,
-      "tag": "0068_fuzzy_quasar",
-      "breakpoints": true
-    },
-    {
-      "idx": 69,
-      "version": "7",
-      "when": 1771062933912,
-      "tag": "0069_broad_hellfire_club",
-      "breakpoints": true
-    },
-    {
-      "idx": 70,
-      "version": "7",
-      "when": 1771073914978,
-      "tag": "0070_warm_lilandra",
-      "breakpoints": true
-    },
-    {
-      "idx": 71,
-      "version": "7",
-      "when": 1771075313248,
-      "tag": "0071_motionless_wind_dancer",
-      "breakpoints": true
-    },
-    {
-      "idx": 72,
-      "version": "7",
-      "when": 1771110659983,
-      "tag": "0072_absurd_gwen_stacy",
-      "breakpoints": true
-    },
-    {
-      "idx": 73,
-      "version": "7",
-      "when": 1771116859658,
-      "tag": "0073_minor_franklin_richards",
+      "when": 1771164248361,
+      "tag": "0068_flaky_swarm",
       "breakpoints": true
     }
   ]

+ 21 - 418
src/app/[locale]/settings/providers/_components/endpoint-latency-sparkline.tsx

@@ -3,8 +3,8 @@
 import { useQuery } from "@tanstack/react-query";
 import { useMemo } from "react";
 import { Line, LineChart, ResponsiveContainer, Tooltip, YAxis } from "recharts";
-import { getProviderEndpointProbeLogs } from "@/actions/provider-endpoints";
 import { useInViewOnce } from "@/lib/hooks/use-in-view-once";
+import { type ProbeLog, probeLogsBatcher } from "@/lib/provider-endpoints/probe-logs-batcher";
 import { cn } from "@/lib/utils";
 
 type SparkPoint = {
@@ -14,46 +14,6 @@ type SparkPoint = {
   timestamp?: number;
 };
 
-type ProbeLog = {
-  ok: boolean;
-  latencyMs: number | null;
-  createdAt?: string | number | Date | null;
-};
-
-function normalizeProbeLog(value: unknown): ProbeLog | null {
-  if (!value || typeof value !== "object") return null;
-
-  const rawOk = (value as { ok?: unknown }).ok;
-  if (typeof rawOk !== "boolean") return null;
-
-  const rawLatencyMs = (value as { latencyMs?: unknown }).latencyMs;
-  const latencyMs =
-    typeof rawLatencyMs === "number" && Number.isFinite(rawLatencyMs) ? rawLatencyMs : null;
-
-  const rawCreatedAt = (value as { createdAt?: unknown }).createdAt;
-  const createdAt =
-    rawCreatedAt === undefined ||
-    rawCreatedAt === null ||
-    typeof rawCreatedAt === "string" ||
-    typeof rawCreatedAt === "number" ||
-    rawCreatedAt instanceof Date
-      ? rawCreatedAt
-      : undefined;
-
-  return { ok: rawOk, latencyMs, createdAt };
-}
-
-function normalizeProbeLogs(value: unknown): ProbeLog[] {
-  if (!Array.isArray(value)) return [];
-
-  const logs: ProbeLog[] = [];
-  for (const item of value) {
-    const normalized = normalizeProbeLog(item);
-    if (normalized) logs.push(normalized);
-  }
-  return logs;
-}
-
 function formatLatency(ms: number | null): string {
   if (ms === null) return "-";
   if (ms < 1000) return `${Math.round(ms)}ms`;
@@ -79,364 +39,27 @@ function CustomTooltip({
   );
 }
 
-function normalizeProbeLogsByEndpointId(data: unknown): Record<number, ProbeLog[]> | null {
-  if (!data || typeof data !== "object") return null;
-
-  if (Array.isArray(data)) {
-    const map: Record<number, ProbeLog[]> = {};
-    for (const item of data) {
-      if (!item || typeof item !== "object") continue;
-      const endpointId = (item as { endpointId?: unknown }).endpointId;
-      const logs = (item as { logs?: unknown }).logs;
-      if (typeof endpointId !== "number" || !Array.isArray(logs)) continue;
-      map[endpointId] = normalizeProbeLogs(logs);
-    }
-    return map;
-  }
-
-  const obj = data as Record<string, unknown>;
-
-  const logsByEndpointId = obj.logsByEndpointId;
-  if (logsByEndpointId && typeof logsByEndpointId === "object") {
-    const raw = logsByEndpointId as Record<string, unknown>;
-    const map: Record<number, ProbeLog[]> = {};
-    for (const [k, v] of Object.entries(raw)) {
-      const endpointId = Number.parseInt(k, 10);
-      if (!Number.isFinite(endpointId) || !Array.isArray(v)) continue;
-      map[endpointId] = normalizeProbeLogs(v);
-    }
-    return map;
-  }
-
-  const items = obj.items;
-  if (Array.isArray(items)) {
-    const map: Record<number, ProbeLog[]> = {};
-    for (const item of items) {
-      if (!item || typeof item !== "object") continue;
-      const endpointId = (item as { endpointId?: unknown }).endpointId;
-      const logs = (item as { logs?: unknown }).logs;
-      if (typeof endpointId !== "number" || !Array.isArray(logs)) continue;
-      map[endpointId] = normalizeProbeLogs(logs);
-    }
-    return map;
-  }
-
-  return null;
-}
-
-let isBatchProbeLogsEndpointAvailable: boolean | undefined;
-let batchProbeLogsEndpointDisabledAt: number | null = null;
-const BATCH_PROBE_LOGS_RETRY_INTERVAL_MS = 5 * 60 * 1000;
-
-function isBatchProbeLogsDisabled(): boolean {
-  if (isBatchProbeLogsEndpointAvailable !== false) return false;
-  if (batchProbeLogsEndpointDisabledAt === null) {
-    // Defensive:避免异常态(disabledAt 丢失)导致永久禁用 batch 路由
-    isBatchProbeLogsEndpointAvailable = undefined;
-    return false;
-  }
-  if (Date.now() - batchProbeLogsEndpointDisabledAt > BATCH_PROBE_LOGS_RETRY_INTERVAL_MS) {
-    isBatchProbeLogsEndpointAvailable = undefined;
-    batchProbeLogsEndpointDisabledAt = null;
-    return false;
-  }
-  return true;
-}
-
-async function tryFetchBatchProbeLogsByEndpointIds(
-  endpointIds: number[],
-  limit: number
-): Promise<Record<number, ProbeLog[]> | null> {
-  if (endpointIds.length <= 1) return null;
-  if (isBatchProbeLogsDisabled()) return null;
-  if (process.env.NODE_ENV === "test") return null;
-
-  const MAX_ENDPOINT_IDS_PER_BATCH = 500;
-  const chunks: number[][] = [];
-  for (let index = 0; index < endpointIds.length; index += MAX_ENDPOINT_IDS_PER_BATCH) {
-    chunks.push(endpointIds.slice(index, index + MAX_ENDPOINT_IDS_PER_BATCH));
-  }
-
-  const merged: Record<number, ProbeLog[]> = {};
-  const fallbackEndpointIds = new Set<number>();
-  const missingFromSuccessfulChunks = new Set<number>();
-  let didAnyChunkSucceed = false;
-  let didAnyChunkFail = false;
-  let didAnyChunk404 = false;
-
-  for (const chunk of chunks) {
-    try {
-      const res = await fetch("/api/actions/providers/batchGetProviderEndpointProbeLogs", {
-        method: "POST",
-        headers: { "content-type": "application/json" },
-        credentials: "same-origin",
-        body: JSON.stringify({ endpointIds: chunk, limit }),
-      });
-
-      if (res.status === 404) {
-        didAnyChunkFail = true;
-        didAnyChunk404 = true;
-
-        // 404 通常意味着路由不存在(旧版本/未部署)。滚动发布场景下可能出现 404 与成功并存:
-        // - 若本次请求存在任一成功 chunk,则视为 batch 路由可用,仅对 404 的 chunk 降级。
-        // - 仅当所有 chunk 都 404 且无任何成功时,才短暂禁用 batch 路由,避免持续打 404。
-
-        for (const endpointId of chunk) fallbackEndpointIds.add(endpointId);
-        continue;
-      }
-
-      if (!res.ok) {
-        didAnyChunkFail = true;
-        for (const endpointId of chunk) fallbackEndpointIds.add(endpointId);
-        continue;
-      }
-
-      const json = (await res.json()) as { ok?: unknown; data?: unknown };
-      if (json.ok !== true) {
-        didAnyChunkFail = true;
-        for (const endpointId of chunk) fallbackEndpointIds.add(endpointId);
-        continue;
-      }
-
-      const normalized = normalizeProbeLogsByEndpointId(json.data);
-      if (!normalized) {
-        didAnyChunkFail = true;
-        for (const endpointId of chunk) fallbackEndpointIds.add(endpointId);
-        continue;
-      }
-
-      didAnyChunkSucceed = true;
-
-      const normalizedEndpointIds = new Set<number>();
-      for (const [endpointId, logs] of Object.entries(normalized)) {
-        const id = Number(endpointId);
-        normalizedEndpointIds.add(id);
-        merged[id] = logs;
-      }
-
-      for (const endpointId of chunk) {
-        if (!normalizedEndpointIds.has(endpointId)) missingFromSuccessfulChunks.add(endpointId);
-      }
-    } catch {
-      didAnyChunkFail = true;
-      for (const endpointId of chunk) fallbackEndpointIds.add(endpointId);
-    }
-  }
-
-  if (!didAnyChunkSucceed) {
-    if (didAnyChunk404) {
-      isBatchProbeLogsEndpointAvailable = false;
-      batchProbeLogsEndpointDisabledAt = Date.now();
-    }
-    return null;
-  }
-
-  // 至少有一个 chunk 成功,说明 batch 路由可用(允许部分失败并按需降级)。
-  isBatchProbeLogsEndpointAvailable = true;
-  batchProbeLogsEndpointDisabledAt = null;
-
-  if (!didAnyChunkFail) {
-    return merged;
-  }
-
-  const endpointIdsToFetchIndividually = new Set<number>();
-  for (const endpointId of fallbackEndpointIds) {
-    if (merged[endpointId] === undefined) endpointIdsToFetchIndividually.add(endpointId);
-  }
-  for (const endpointId of missingFromSuccessfulChunks) {
-    if (merged[endpointId] === undefined) endpointIdsToFetchIndividually.add(endpointId);
-  }
-
-  if (endpointIdsToFetchIndividually.size === 0) return merged;
-
-  const rest = await fetchProbeLogsByEndpointIdsIndividually(
-    Array.from(endpointIdsToFetchIndividually),
-    limit
-  ).catch(() => null);
-
-  if (rest) {
-    for (const [endpointId, logs] of Object.entries(rest)) {
-      merged[Number(endpointId)] = logs;
-    }
-  }
-
-  return merged;
-}
-
-async function fetchProbeLogsByEndpointIdsIndividually(
-  endpointIds: number[],
-  limit: number
-): Promise<Record<number, ProbeLog[]>> {
-  const map: Record<number, ProbeLog[]> = {};
-  const concurrency = 4;
-  let idx = 0;
-
-  const workers = Array.from({ length: Math.min(concurrency, endpointIds.length) }, async () => {
-    for (;;) {
-      const currentIndex = idx++;
-      if (currentIndex >= endpointIds.length) return;
-      const endpointId = endpointIds[currentIndex];
-
-      try {
-        const res = await getProviderEndpointProbeLogs({
-          endpointId,
-          limit,
-        });
-        map[endpointId] = res.ok && res.data ? normalizeProbeLogs(res.data.logs) : [];
-      } catch {
-        map[endpointId] = [];
-      }
-    }
-  });
-
-  await Promise.all(workers);
-  return map;
-}
-
-async function fetchProbeLogsByEndpointIds(
-  endpointIds: number[],
-  limit: number
-): Promise<Record<number, ProbeLog[]>> {
-  const batched = await tryFetchBatchProbeLogsByEndpointIds(endpointIds, limit);
-  if (batched) return batched;
-  return fetchProbeLogsByEndpointIdsIndividually(endpointIds, limit);
-}
-
-type BatchRequest = {
-  endpointId: number;
-  resolve: (logs: ProbeLog[]) => void;
-  reject: (error: unknown) => void;
-};
-
-function createAbortError(signal?: AbortSignal): unknown {
-  if (!signal) return new Error("Aborted");
-  if (signal.reason) return signal.reason;
-
-  try {
-    return new DOMException("Aborted", "AbortError");
-  } catch {
-    return new Error("Aborted");
-  }
-}
-
-class ProbeLogsBatcher {
-  private readonly pendingByLimit = new Map<number, Map<number, BatchRequest[]>>();
-  private flushTimer: ReturnType<typeof setTimeout> | null = null;
-
-  load(endpointId: number, limit: number, options?: { signal?: AbortSignal }): Promise<ProbeLog[]> {
-    return new Promise((resolve, reject) => {
-      const signal = options?.signal;
-      if (signal?.aborted) {
-        reject(createAbortError(signal));
-        return;
-      }
-
-      let settled = false;
-      let request: BatchRequest;
-
-      const onAbort = () => {
-        if (settled) return;
-        settled = true;
-        this.removePendingRequest(limit, endpointId, request);
-        this.maybeCancelFlushTimer();
-        reject(createAbortError(signal));
-      };
-
-      request = {
-        endpointId,
-        resolve: (logs) => {
-          if (settled) return;
-          settled = true;
-          signal?.removeEventListener("abort", onAbort);
-          resolve(logs);
-        },
-        reject: (error) => {
-          if (settled) return;
-          settled = true;
-          signal?.removeEventListener("abort", onAbort);
-          reject(error);
-        },
-      };
-
-      if (signal) {
-        signal.addEventListener("abort", onAbort, { once: true });
-      }
-
-      const group = this.pendingByLimit.get(limit) ?? new Map<number, BatchRequest[]>();
-      const list = group.get(endpointId) ?? [];
-      list.push(request);
-      group.set(endpointId, list);
-      this.pendingByLimit.set(limit, group);
-
-      if (this.flushTimer) return;
-      const delayMs = process.env.NODE_ENV === "test" ? 0 : 10;
-      this.flushTimer = setTimeout(() => {
-        this.flushTimer = null;
-        void this.flush().catch(() => {});
-      }, delayMs);
-    });
-  }
-
-  private maybeCancelFlushTimer() {
-    if (!this.flushTimer) return;
-    if (this.pendingByLimit.size > 0) return;
-    clearTimeout(this.flushTimer);
-    this.flushTimer = null;
-  }
-
-  private removePendingRequest(limit: number, endpointId: number, request: BatchRequest) {
-    const group = this.pendingByLimit.get(limit);
-    if (!group) return;
-    const list = group.get(endpointId);
-    if (!list) return;
-
-    const next = list.filter((item) => item !== request);
-    if (next.length > 0) {
-      group.set(endpointId, next);
-      return;
-    }
-
-    group.delete(endpointId);
-    if (group.size === 0) {
-      this.pendingByLimit.delete(limit);
-    }
-  }
-
-  private async flush() {
-    const snapshot = new Map(this.pendingByLimit);
-    this.pendingByLimit.clear();
-
-    try {
-      await Promise.all(
-        Array.from(snapshot.entries(), async ([limit, group]) => {
-          const endpointIds = Array.from(group.keys());
-          if (endpointIds.length === 0) return;
-
-          try {
-            const map = await fetchProbeLogsByEndpointIds(endpointIds, limit);
-            for (const [endpointId, requests] of group.entries()) {
-              const logs = map[endpointId] ?? [];
-              for (const req of requests) req.resolve(logs);
-            }
-          } catch (error) {
-            for (const requests of group.values()) {
-              for (const req of requests) req.reject(error);
-            }
-          }
-        })
-      );
-    } catch (error) {
-      for (const group of snapshot.values()) {
-        for (const requests of group.values()) {
-          for (const req of requests) req.reject(error);
-        }
-      }
-    }
-  }
+function probeLogsToSparkPoints(logs: ProbeLog[]): SparkPoint[] {
+  const points: SparkPoint[] = new Array(logs.length);
+  for (let i = logs.length - 1, idx = 0; i >= 0; i -= 1, idx += 1) {
+    const log = logs[i];
+    const rawTimestamp =
+      log.createdAt === undefined || log.createdAt === null
+        ? undefined
+        : new Date(log.createdAt).getTime();
+    const timestamp =
+      rawTimestamp !== undefined && Number.isFinite(rawTimestamp) ? rawTimestamp : undefined;
+
+    points[idx] = {
+      index: idx,
+      latencyMs: log.latencyMs ?? null,
+      ok: log.ok,
+      timestamp,
+    };
+  }
+  return points;
 }
 
-const probeLogsBatcher = new ProbeLogsBatcher();
-
 export function EndpointLatencySparkline(props: { endpointId: number; limit?: number }) {
   const limit = props.limit ?? 12;
   const { ref, isInView } = useInViewOnce<HTMLDivElement>();
@@ -445,26 +68,7 @@ export function EndpointLatencySparkline(props: { endpointId: number; limit?: nu
     queryKey: ["endpoint-probe-logs", props.endpointId, limit],
     queryFn: async ({ signal }): Promise<SparkPoint[]> => {
       const logs = await probeLogsBatcher.load(props.endpointId, limit, { signal });
-
-      const points: SparkPoint[] = new Array(logs.length);
-      for (let i = logs.length - 1, idx = 0; i >= 0; i -= 1, idx += 1) {
-        const log = logs[i];
-        const rawTimestamp =
-          log.createdAt === undefined || log.createdAt === null
-            ? undefined
-            : new Date(log.createdAt).getTime();
-        const timestamp =
-          rawTimestamp !== undefined && Number.isFinite(rawTimestamp) ? rawTimestamp : undefined;
-
-        points[idx] = {
-          index: idx,
-          latencyMs: log.latencyMs ?? null,
-          ok: log.ok,
-          timestamp,
-        };
-      }
-
-      return points;
+      return probeLogsToSparkPoints(logs);
     },
     staleTime: 30_000,
     refetchOnWindowFocus: false,
@@ -487,7 +91,6 @@ export function EndpointLatencySparkline(props: { endpointId: number; limit?: nu
     return count > 0 ? sum / count : null;
   }, [points]);
 
-  // useInViewOnce 保证 isInView 只会 false -> true,不会反复切回,因此不会因 refetch 闪烁骨架屏。
   const showSkeleton = !isInView || isLoading;
 
   if (showSkeleton) {

+ 6 - 12
src/app/[locale]/settings/providers/_components/provider-endpoint-hover.tsx

@@ -11,6 +11,7 @@ import {
 } from "@/actions/provider-endpoints";
 import { Badge } from "@/components/ui/badge";
 import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
+import { createAbortError } from "@/lib/abort-utils";
 import { cn } from "@/lib/utils";
 import type { ProviderEndpoint, ProviderType } from "@/types/provider";
 import { type EndpointCircuitState, getEndpointStatusModel } from "./endpoint-status";
@@ -36,17 +37,6 @@ type VendorStatsDeferred = {
   reject: (reason: unknown) => void;
 };
 
-function createAbortError(signal?: AbortSignal): unknown {
-  if (!signal) return new Error("Aborted");
-  if (signal.reason) return signal.reason;
-
-  try {
-    return new DOMException("Aborted", "AbortError");
-  } catch {
-    return new Error("Aborted");
-  }
-}
-
 class VendorTypeEndpointStatsBatcher {
   private readonly pendingVendorIdsByProviderType = new Map<ProviderType, Set<number>>();
   private readonly deferredByProviderTypeVendorId = new Map<
@@ -124,7 +114,11 @@ class VendorTypeEndpointStatsBatcher {
 
       this.flushTimer = setTimeout(() => {
         this.flushTimer = null;
-        void this.flush().catch(() => {});
+        void this.flush().catch((error) => {
+          if (process.env.NODE_ENV !== "test") {
+            console.error("[VendorTypeEndpointStatsBatcher] flush failed", error);
+          }
+        });
       }, 0);
     });
   }

+ 10 - 0
src/lib/abort-utils.ts

@@ -0,0 +1,10 @@
+export function createAbortError(signal?: AbortSignal): unknown {
+  if (!signal) return new Error("Aborted");
+  if (signal.reason) return signal.reason;
+
+  try {
+    return new DOMException("Aborted", "AbortError");
+  } catch {
+    return new Error("Aborted");
+  }
+}

+ 79 - 0
src/lib/cache/ttl-map.ts

@@ -0,0 +1,79 @@
+export class TTLMap<K, V> {
+  private readonly ttlMs: number;
+  private readonly maxSize: number;
+  private readonly store = new Map<K, { value: V; expiresAt: number }>();
+
+  constructor(opts: { ttlMs: number; maxSize: number }) {
+    this.ttlMs = opts.ttlMs;
+    this.maxSize = opts.maxSize;
+  }
+
+  get(key: K): V | undefined {
+    const entry = this.store.get(key);
+    if (!entry) return undefined;
+
+    if (entry.expiresAt <= Date.now()) {
+      this.store.delete(key);
+      return undefined;
+    }
+
+    // LRU bump: delete and re-insert to move to end of iteration order
+    this.store.delete(key);
+    this.store.set(key, entry);
+    return entry.value;
+  }
+
+  set(key: K, value: V): void {
+    // Delete first so re-insert goes to end (LRU order)
+    this.store.delete(key);
+
+    if (this.store.size >= this.maxSize) {
+      this.evict();
+    }
+
+    this.store.set(key, { value, expiresAt: Date.now() + this.ttlMs });
+  }
+
+  delete(key: K): boolean {
+    return this.store.delete(key);
+  }
+
+  has(key: K): boolean {
+    const entry = this.store.get(key);
+    if (!entry) return false;
+
+    if (entry.expiresAt <= Date.now()) {
+      this.store.delete(key);
+      return false;
+    }
+
+    return true;
+  }
+
+  get size(): number {
+    return this.store.size;
+  }
+
+  private evict(): void {
+    const now = Date.now();
+
+    // First pass: remove expired entries
+    for (const [k, v] of this.store) {
+      if (v.expiresAt <= now) {
+        this.store.delete(k);
+      }
+    }
+
+    // If still at capacity, evict oldest 10%
+    if (this.store.size >= this.maxSize) {
+      const evictCount = Math.max(1, Math.ceil(this.maxSize * 0.1));
+      let remaining = evictCount;
+
+      for (const k of this.store.keys()) {
+        this.store.delete(k);
+        remaining -= 1;
+        if (remaining <= 0) break;
+      }
+    }
+  }
+}

+ 1 - 16
src/lib/endpoint-circuit-breaker.ts

@@ -35,22 +35,7 @@ const loadedFromRedisAt = new Map<number, number>();
 const redisSyncInFlight = new Map<number, Promise<void>>();
 const REDIS_SYNC_TTL_MS = 1_000;
 
-function readPositiveIntEnv(name: string, fallback: number): number {
-  const raw = process.env[name];
-  if (!raw) return fallback;
-
-  const parsed = Number.parseInt(raw, 10);
-  if (!Number.isFinite(parsed) || parsed <= 0) {
-    return fallback;
-  }
-
-  return parsed;
-}
-
-const ENDPOINT_HEALTH_CACHE_MAX_SIZE = readPositiveIntEnv(
-  "ENDPOINT_CIRCUIT_HEALTH_CACHE_MAX_SIZE",
-  10_000
-);
+const ENDPOINT_HEALTH_CACHE_MAX_SIZE = 10_000;
 
 function bumpLRU<K, V>(map: Map<K, V>, key: K): void {
   if (!map.has(key)) return;

+ 27 - 116
src/lib/hooks/use-in-view-once.ts

@@ -1,20 +1,15 @@
-import { useCallback, useEffect, useMemo, useState } from "react";
-
-type StableIntersectionObserverInit = IntersectionObserverInit & {
-  delay?: number;
-  trackVisibility?: boolean;
-};
+import { useCallback, useEffect, useState } from "react";
 
 type ObserverTargetCallback = (entry: IntersectionObserverEntry) => void;
-type ObserverRootKey = Element | Document;
 
-const sharedObserversForNullRoot = new Map<string, SharedIntersectionObserver>();
-const sharedObserversByRoot = new WeakMap<
-  ObserverRootKey,
-  Map<string, SharedIntersectionObserver>
->();
+const DEFAULT_OPTIONS: IntersectionObserverInit = {
+  rootMargin: "200px",
+  threshold: 0,
+};
 
-function getObserverOptionsKey(options: StableIntersectionObserverInit): string {
+const sharedObservers = new Map<string, SharedIntersectionObserver>();
+
+function getObserverOptionsKey(options: IntersectionObserverInit): string {
   const rootMargin = options.rootMargin ?? "0px";
   const threshold = options.threshold;
   const thresholdKey =
@@ -23,71 +18,17 @@ function getObserverOptionsKey(options: StableIntersectionObserverInit): string
       : Array.isArray(threshold)
         ? threshold.join(",")
         : String(threshold);
-  const trackVisibilityKey =
-    options.trackVisibility === undefined ? "" : options.trackVisibility ? "1" : "0";
-  const delayKey = options.delay === undefined ? "" : String(options.delay);
-  return `${rootMargin}|${thresholdKey}|${trackVisibilityKey}|${delayKey}`;
-}
-
-function releaseSharedObserver(
-  root: ObserverRootKey | null,
-  optionsKey: string,
-  observer: SharedIntersectionObserver
-): void {
-  if (root === null) {
-    if (sharedObserversForNullRoot.get(optionsKey) === observer) {
-      sharedObserversForNullRoot.delete(optionsKey);
-    }
-    return;
-  }
-
-  const pool = sharedObserversByRoot.get(root);
-  if (!pool) return;
-  if (pool.get(optionsKey) !== observer) return;
-
-  pool.delete(optionsKey);
-  if (pool.size === 0) {
-    sharedObserversByRoot.delete(root);
-  }
-}
-
-function getSharedObserver(options: StableIntersectionObserverInit): SharedIntersectionObserver {
-  const root = options.root ?? null;
-  const optionsKey = getObserverOptionsKey(options);
-
-  if (root === null) {
-    const existing = sharedObserversForNullRoot.get(optionsKey);
-    if (existing) return existing;
-
-    const observer = new SharedIntersectionObserver(root, optionsKey, options);
-    sharedObserversForNullRoot.set(optionsKey, observer);
-    return observer;
-  }
-
-  const rootKey = root as ObserverRootKey;
-  const pool = sharedObserversByRoot.get(rootKey) ?? new Map<string, SharedIntersectionObserver>();
-  if (!sharedObserversByRoot.has(rootKey)) {
-    sharedObserversByRoot.set(rootKey, pool);
-  }
-
-  const existing = pool.get(optionsKey);
-  if (existing) return existing;
-
-  const observer = new SharedIntersectionObserver(rootKey, optionsKey, options);
-  pool.set(optionsKey, observer);
-  return observer;
+  return `${rootMargin}|${thresholdKey}`;
 }
 
 class SharedIntersectionObserver {
   private readonly callbacksByTarget = new Map<Element, Set<ObserverTargetCallback>>();
   private readonly observer: IntersectionObserver;
+  private readonly optionsKey: string;
   private disposed = false;
 
-  constructor(
-    private readonly root: ObserverRootKey | null,
-    private readonly optionsKey: string,
-    options: StableIntersectionObserverInit
-  ) {
+  constructor(optionsKey: string, options: IntersectionObserverInit) {
+    this.optionsKey = optionsKey;
     this.observer = new IntersectionObserver((entries) => {
       for (const entry of entries) {
         const callbacks = this.callbacksByTarget.get(entry.target);
@@ -144,60 +85,30 @@ class SharedIntersectionObserver {
     if (this.disposed) return;
     this.disposed = true;
     this.observer.disconnect();
-    releaseSharedObserver(this.root, this.optionsKey, this);
+    sharedObservers.delete(this.optionsKey);
   }
 }
 
-function useStableIntersectionObserverOptions(options?: IntersectionObserverInit) {
-  const stableOptions = options as StableIntersectionObserverInit | undefined;
-
-  // 关键点:保持 `{ rootMargin: "200px", ...options }` 的语义不变;
-  // 并避免在渲染期间读写 ref,减少严格模式下的潜在隐患。
-  const root = stableOptions?.root ?? null;
-  const rootMargin = stableOptions?.rootMargin ?? "200px";
-  const threshold = stableOptions?.threshold;
-  const thresholdKey =
-    threshold === undefined
-      ? "0"
-      : Array.isArray(threshold)
-        ? threshold.join(",")
-        : String(threshold);
-  const stableThreshold = useMemo<StableIntersectionObserverInit["threshold"]>(() => {
-    if (!thresholdKey) return 0;
-
-    if (thresholdKey.includes(",")) {
-      const values = thresholdKey
-        .split(",")
-        .map((value) => Number.parseFloat(value))
-        .filter((value) => Number.isFinite(value));
-
-      return values.length > 0 ? values : 0;
-    }
+function getSharedObserver(options: IntersectionObserverInit): SharedIntersectionObserver {
+  const key = getObserverOptionsKey(options);
+  const existing = sharedObservers.get(key);
+  if (existing) return existing;
 
-    const value = Number.parseFloat(thresholdKey);
-    return Number.isFinite(value) ? value : 0;
-  }, [thresholdKey]);
-  const trackVisibility = stableOptions?.trackVisibility;
-  const delay = stableOptions?.delay;
-
-  return useMemo<StableIntersectionObserverInit>(() => {
-    const init: StableIntersectionObserverInit = { root, rootMargin, threshold: stableThreshold };
-    if (trackVisibility !== undefined) init.trackVisibility = trackVisibility;
-    if (delay !== undefined) init.delay = delay;
-    return init;
-  }, [delay, root, rootMargin, stableThreshold, trackVisibility]);
+  const observer = new SharedIntersectionObserver(key, options);
+  sharedObservers.set(key, observer);
+  return observer;
 }
 
 /**
- * 仅在元素首次进入视窗(含 rootMargin 预取)后变为 true 的 Hook。
+ * Returns true once an element enters the viewport (with 200px pre-fetch margin).
  *
- * - 用于将“按行/按卡片”的请求从挂载时触发,延迟到可视区域附近触发,避免首屏请求风暴。
- * - 在 test 环境或缺少 IntersectionObserver 时会直接视为可见,保证可预测性。
+ * Delays per-row/per-card requests until elements are near-visible, avoiding
+ * request storms on mount. In test environments or without IntersectionObserver,
+ * elements are treated as immediately visible.
  */
-export function useInViewOnce<T extends Element>(options?: IntersectionObserverInit) {
+export function useInViewOnce<T extends Element>() {
   const [element, setElement] = useState<T | null>(null);
   const [isInView, setIsInView] = useState(false);
-  const stableOptions = useStableIntersectionObserverOptions(options);
 
   const ref = useCallback((node: T | null) => {
     setElement(node);
@@ -214,7 +125,7 @@ export function useInViewOnce<T extends Element>(options?: IntersectionObserverI
     if (!element) return;
 
     let disposed = false;
-    const sharedObserver = getSharedObserver(stableOptions);
+    const sharedObserver = getSharedObserver(DEFAULT_OPTIONS);
     let unsubscribe: (() => void) | null = null;
 
     const onEntry = (entry: IntersectionObserverEntry) => {
@@ -232,7 +143,7 @@ export function useInViewOnce<T extends Element>(options?: IntersectionObserverI
       unsubscribe?.();
       unsubscribe = null;
     };
-  }, [element, isInView, stableOptions]);
+  }, [element, isInView]);
 
   return { ref, isInView };
 }

+ 55 - 0
src/lib/provider-endpoints/leader-lock.ts

@@ -139,3 +139,58 @@ export async function releaseLeaderLock(lock: LeaderLock): Promise<void> {
     });
   }
 }
+
+export function startLeaderLockKeepAlive(opts: {
+  getLock: () => LeaderLock | undefined;
+  clearLock: () => void;
+  ttlMs: number;
+  logTag: string;
+  onLost: () => void;
+}): { stop: () => void } {
+  let stopped = false;
+  let renewing = false;
+  let intervalId: ReturnType<typeof setInterval> | undefined;
+
+  const stop = () => {
+    if (stopped) return;
+    stopped = true;
+    if (intervalId) clearInterval(intervalId);
+  };
+
+  const tick = async () => {
+    if (stopped || renewing) return;
+
+    const current = opts.getLock();
+    if (!current) {
+      stop();
+      opts.onLost();
+      return;
+    }
+
+    renewing = true;
+    try {
+      const ok = await renewLeaderLock(current, opts.ttlMs);
+      if (!ok) {
+        opts.clearLock();
+        stop();
+        opts.onLost();
+        logger.warn(`[${opts.logTag}] Lost leader lock during operation`, {
+          key: current.key,
+          lockType: current.lockType,
+        });
+      }
+    } finally {
+      renewing = false;
+    }
+  };
+
+  const intervalMs = Math.max(1000, Math.floor(opts.ttlMs / 2));
+  intervalId = setInterval(() => {
+    void tick();
+  }, intervalMs);
+
+  const timer = intervalId as unknown as { unref?: () => void };
+  timer.unref?.();
+
+  return { stop };
+}

+ 12 - 53
src/lib/provider-endpoints/probe-log-cleanup.ts

@@ -3,7 +3,7 @@ import {
   acquireLeaderLock,
   type LeaderLock,
   releaseLeaderLock,
-  renewLeaderLock,
+  startLeaderLockKeepAlive,
 } from "@/lib/provider-endpoints/leader-lock";
 import { deleteProviderEndpointProbeLogsBeforeDateBatch } from "@/repository";
 
@@ -32,55 +32,6 @@ const cleanupState = globalThis as unknown as {
   __CCH_ENDPOINT_PROBE_LOG_CLEANUP_RUNNING__?: boolean;
 };
 
-function startLeaderLockKeepAlive(onLost: () => void): () => void {
-  let stopped = false;
-  let renewing = false;
-  let intervalId: ReturnType<typeof setInterval> | undefined;
-
-  const stop = () => {
-    if (stopped) return;
-    stopped = true;
-    if (intervalId) clearInterval(intervalId);
-  };
-
-  const tick = async () => {
-    if (stopped || renewing) return;
-
-    const current = cleanupState.__CCH_ENDPOINT_PROBE_LOG_CLEANUP_LOCK__;
-    if (!current) {
-      stop();
-      onLost();
-      return;
-    }
-
-    renewing = true;
-    try {
-      const ok = await renewLeaderLock(current, LOCK_TTL_MS);
-      if (!ok) {
-        cleanupState.__CCH_ENDPOINT_PROBE_LOG_CLEANUP_LOCK__ = undefined;
-        stop();
-        onLost();
-        logger.warn("[EndpointProbeLogCleanup] Lost leader lock during cleanup", {
-          key: current.key,
-          lockType: current.lockType,
-        });
-      }
-    } finally {
-      renewing = false;
-    }
-  };
-
-  const intervalMs = Math.max(1000, Math.floor(LOCK_TTL_MS / 2));
-  intervalId = setInterval(() => {
-    void tick();
-  }, intervalMs);
-
-  const timer = intervalId as unknown as { unref?: () => void };
-  timer.unref?.();
-
-  return stop;
-}
-
 async function runCleanupOnce(): Promise<void> {
   if (cleanupState.__CCH_ENDPOINT_PROBE_LOG_CLEANUP_RUNNING__) {
     return;
@@ -100,9 +51,17 @@ async function runCleanupOnce(): Promise<void> {
 
     cleanupState.__CCH_ENDPOINT_PROBE_LOG_CLEANUP_LOCK__ = lock;
 
-    stopKeepAlive = startLeaderLockKeepAlive(() => {
-      leadershipLost = true;
-    });
+    stopKeepAlive = startLeaderLockKeepAlive({
+      getLock: () => cleanupState.__CCH_ENDPOINT_PROBE_LOG_CLEANUP_LOCK__,
+      clearLock: () => {
+        cleanupState.__CCH_ENDPOINT_PROBE_LOG_CLEANUP_LOCK__ = undefined;
+      },
+      ttlMs: LOCK_TTL_MS,
+      logTag: "EndpointProbeLogCleanup",
+      onLost: () => {
+        leadershipLost = true;
+      },
+    }).stop;
 
     const now = Date.now();
     const retentionMs = Math.max(0, RETENTION_DAYS) * 24 * 60 * 60 * 1000;

+ 387 - 0
src/lib/provider-endpoints/probe-logs-batcher.ts

@@ -0,0 +1,387 @@
+import { getProviderEndpointProbeLogs } from "@/actions/provider-endpoints";
+import { createAbortError } from "@/lib/abort-utils";
+
+export type ProbeLog = {
+  ok: boolean;
+  latencyMs: number | null;
+  createdAt?: string | number | Date | null;
+};
+
+function normalizeProbeLog(value: unknown): ProbeLog | null {
+  if (!value || typeof value !== "object") return null;
+
+  const rawOk = (value as { ok?: unknown }).ok;
+  if (typeof rawOk !== "boolean") return null;
+
+  const rawLatencyMs = (value as { latencyMs?: unknown }).latencyMs;
+  const latencyMs =
+    typeof rawLatencyMs === "number" && Number.isFinite(rawLatencyMs) ? rawLatencyMs : null;
+
+  const rawCreatedAt = (value as { createdAt?: unknown }).createdAt;
+  const createdAt =
+    rawCreatedAt === undefined ||
+    rawCreatedAt === null ||
+    typeof rawCreatedAt === "string" ||
+    typeof rawCreatedAt === "number" ||
+    rawCreatedAt instanceof Date
+      ? rawCreatedAt
+      : undefined;
+
+  return { ok: rawOk, latencyMs, createdAt };
+}
+
+function normalizeProbeLogs(value: unknown): ProbeLog[] {
+  if (!Array.isArray(value)) return [];
+
+  const logs: ProbeLog[] = [];
+  for (const item of value) {
+    const normalized = normalizeProbeLog(item);
+    if (normalized) logs.push(normalized);
+  }
+  return logs;
+}
+
+function normalizeProbeLogsByEndpointId(data: unknown): Record<number, ProbeLog[]> | null {
+  if (!data || typeof data !== "object") return null;
+
+  if (Array.isArray(data)) {
+    const map: Record<number, ProbeLog[]> = {};
+    for (const item of data) {
+      if (!item || typeof item !== "object") continue;
+      const endpointId = (item as { endpointId?: unknown }).endpointId;
+      const logs = (item as { logs?: unknown }).logs;
+      if (typeof endpointId !== "number" || !Array.isArray(logs)) continue;
+      map[endpointId] = normalizeProbeLogs(logs);
+    }
+    return map;
+  }
+
+  const obj = data as Record<string, unknown>;
+
+  const logsByEndpointId = obj.logsByEndpointId;
+  if (logsByEndpointId && typeof logsByEndpointId === "object") {
+    const raw = logsByEndpointId as Record<string, unknown>;
+    const map: Record<number, ProbeLog[]> = {};
+    for (const [k, v] of Object.entries(raw)) {
+      const endpointId = Number.parseInt(k, 10);
+      if (!Number.isFinite(endpointId) || !Array.isArray(v)) continue;
+      map[endpointId] = normalizeProbeLogs(v);
+    }
+    return map;
+  }
+
+  const items = obj.items;
+  if (Array.isArray(items)) {
+    const map: Record<number, ProbeLog[]> = {};
+    for (const item of items) {
+      if (!item || typeof item !== "object") continue;
+      const endpointId = (item as { endpointId?: unknown }).endpointId;
+      const logs = (item as { logs?: unknown }).logs;
+      if (typeof endpointId !== "number" || !Array.isArray(logs)) continue;
+      map[endpointId] = normalizeProbeLogs(logs);
+    }
+    return map;
+  }
+
+  return null;
+}
+
+let isBatchProbeLogsEndpointAvailable: boolean | undefined;
+let batchProbeLogsEndpointDisabledAt: number | null = null;
+const BATCH_PROBE_LOGS_RETRY_INTERVAL_MS = 5 * 60 * 1000;
+
+function isBatchProbeLogsDisabled(): boolean {
+  if (isBatchProbeLogsEndpointAvailable !== false) return false;
+  if (batchProbeLogsEndpointDisabledAt === null) {
+    isBatchProbeLogsEndpointAvailable = undefined;
+    return false;
+  }
+  if (Date.now() - batchProbeLogsEndpointDisabledAt > BATCH_PROBE_LOGS_RETRY_INTERVAL_MS) {
+    isBatchProbeLogsEndpointAvailable = undefined;
+    batchProbeLogsEndpointDisabledAt = null;
+    return false;
+  }
+  return true;
+}
+
+async function tryFetchBatchProbeLogsByEndpointIds(
+  endpointIds: number[],
+  limit: number
+): Promise<Record<number, ProbeLog[]> | null> {
+  if (endpointIds.length <= 1) return null;
+  if (isBatchProbeLogsDisabled()) return null;
+  if (process.env.NODE_ENV === "test") return null;
+
+  const MAX_ENDPOINT_IDS_PER_BATCH = 500;
+  const chunks: number[][] = [];
+  for (let index = 0; index < endpointIds.length; index += MAX_ENDPOINT_IDS_PER_BATCH) {
+    chunks.push(endpointIds.slice(index, index + MAX_ENDPOINT_IDS_PER_BATCH));
+  }
+
+  const merged: Record<number, ProbeLog[]> = {};
+  const fallbackEndpointIds = new Set<number>();
+  const missingFromSuccessfulChunks = new Set<number>();
+  let didAnyChunkSucceed = false;
+  let didAnyChunkFail = false;
+  let didAnyChunk404 = false;
+
+  for (const chunk of chunks) {
+    try {
+      const res = await fetch("/api/actions/providers/batchGetProviderEndpointProbeLogs", {
+        method: "POST",
+        headers: { "content-type": "application/json" },
+        credentials: "same-origin",
+        body: JSON.stringify({ endpointIds: chunk, limit }),
+      });
+
+      if (res.status === 404) {
+        didAnyChunkFail = true;
+        didAnyChunk404 = true;
+
+        for (const endpointId of chunk) fallbackEndpointIds.add(endpointId);
+        continue;
+      }
+
+      if (!res.ok) {
+        didAnyChunkFail = true;
+        for (const endpointId of chunk) fallbackEndpointIds.add(endpointId);
+        continue;
+      }
+
+      const json = (await res.json()) as { ok?: unknown; data?: unknown };
+      if (json.ok !== true) {
+        didAnyChunkFail = true;
+        for (const endpointId of chunk) fallbackEndpointIds.add(endpointId);
+        continue;
+      }
+
+      const normalized = normalizeProbeLogsByEndpointId(json.data);
+      if (!normalized) {
+        didAnyChunkFail = true;
+        for (const endpointId of chunk) fallbackEndpointIds.add(endpointId);
+        continue;
+      }
+
+      didAnyChunkSucceed = true;
+
+      const normalizedEndpointIds = new Set<number>();
+      for (const [endpointId, logs] of Object.entries(normalized)) {
+        const id = Number(endpointId);
+        normalizedEndpointIds.add(id);
+        merged[id] = logs;
+      }
+
+      for (const endpointId of chunk) {
+        if (!normalizedEndpointIds.has(endpointId)) missingFromSuccessfulChunks.add(endpointId);
+      }
+    } catch {
+      didAnyChunkFail = true;
+      for (const endpointId of chunk) fallbackEndpointIds.add(endpointId);
+    }
+  }
+
+  if (!didAnyChunkSucceed) {
+    if (didAnyChunk404) {
+      isBatchProbeLogsEndpointAvailable = false;
+      batchProbeLogsEndpointDisabledAt = Date.now();
+    }
+    return null;
+  }
+
+  isBatchProbeLogsEndpointAvailable = true;
+  batchProbeLogsEndpointDisabledAt = null;
+
+  if (!didAnyChunkFail) {
+    return merged;
+  }
+
+  const endpointIdsToFetchIndividually = new Set<number>();
+  for (const endpointId of fallbackEndpointIds) {
+    if (merged[endpointId] === undefined) endpointIdsToFetchIndividually.add(endpointId);
+  }
+  for (const endpointId of missingFromSuccessfulChunks) {
+    if (merged[endpointId] === undefined) endpointIdsToFetchIndividually.add(endpointId);
+  }
+
+  if (endpointIdsToFetchIndividually.size === 0) return merged;
+
+  const rest = await fetchProbeLogsByEndpointIdsIndividually(
+    Array.from(endpointIdsToFetchIndividually),
+    limit
+  ).catch(() => null);
+
+  if (rest) {
+    for (const [endpointId, logs] of Object.entries(rest)) {
+      merged[Number(endpointId)] = logs;
+    }
+  }
+
+  return merged;
+}
+
+async function fetchProbeLogsByEndpointIdsIndividually(
+  endpointIds: number[],
+  limit: number
+): Promise<Record<number, ProbeLog[]>> {
+  const map: Record<number, ProbeLog[]> = {};
+  const concurrency = 4;
+  let idx = 0;
+
+  const workers = Array.from({ length: Math.min(concurrency, endpointIds.length) }, async () => {
+    for (;;) {
+      const currentIndex = idx++;
+      if (currentIndex >= endpointIds.length) return;
+      const endpointId = endpointIds[currentIndex];
+
+      try {
+        const res = await getProviderEndpointProbeLogs({
+          endpointId,
+          limit,
+        });
+        map[endpointId] = res.ok && res.data ? normalizeProbeLogs(res.data.logs) : [];
+      } catch {
+        map[endpointId] = [];
+      }
+    }
+  });
+
+  await Promise.all(workers);
+  return map;
+}
+
+async function fetchProbeLogsByEndpointIds(
+  endpointIds: number[],
+  limit: number
+): Promise<Record<number, ProbeLog[]>> {
+  const batched = await tryFetchBatchProbeLogsByEndpointIds(endpointIds, limit);
+  if (batched) return batched;
+  return fetchProbeLogsByEndpointIdsIndividually(endpointIds, limit);
+}
+
+type BatchRequest = {
+  endpointId: number;
+  resolve: (logs: ProbeLog[]) => void;
+  reject: (error: unknown) => void;
+};
+
+export class ProbeLogsBatcher {
+  private readonly pendingByLimit = new Map<number, Map<number, BatchRequest[]>>();
+  private flushTimer: ReturnType<typeof setTimeout> | null = null;
+
+  load(endpointId: number, limit: number, options?: { signal?: AbortSignal }): Promise<ProbeLog[]> {
+    return new Promise((resolve, reject) => {
+      const signal = options?.signal;
+      if (signal?.aborted) {
+        reject(createAbortError(signal));
+        return;
+      }
+
+      let settled = false;
+      let request: BatchRequest;
+
+      const onAbort = () => {
+        if (settled) return;
+        settled = true;
+        this.removePendingRequest(limit, endpointId, request);
+        this.maybeCancelFlushTimer();
+        reject(createAbortError(signal));
+      };
+
+      request = {
+        endpointId,
+        resolve: (logs) => {
+          if (settled) return;
+          settled = true;
+          signal?.removeEventListener("abort", onAbort);
+          resolve(logs);
+        },
+        reject: (error) => {
+          if (settled) return;
+          settled = true;
+          signal?.removeEventListener("abort", onAbort);
+          reject(error);
+        },
+      };
+
+      if (signal) {
+        signal.addEventListener("abort", onAbort, { once: true });
+      }
+
+      const group = this.pendingByLimit.get(limit) ?? new Map<number, BatchRequest[]>();
+      const list = group.get(endpointId) ?? [];
+      list.push(request);
+      group.set(endpointId, list);
+      this.pendingByLimit.set(limit, group);
+
+      if (this.flushTimer) return;
+      const delayMs = process.env.NODE_ENV === "test" ? 0 : 10;
+      this.flushTimer = setTimeout(() => {
+        this.flushTimer = null;
+        void this.flush().catch((error) => {
+          if (process.env.NODE_ENV !== "test") {
+            console.error("[ProbeLogsBatcher] flush failed", error);
+          }
+        });
+      }, delayMs);
+    });
+  }
+
+  private maybeCancelFlushTimer() {
+    if (!this.flushTimer) return;
+    if (this.pendingByLimit.size > 0) return;
+    clearTimeout(this.flushTimer);
+    this.flushTimer = null;
+  }
+
+  private removePendingRequest(limit: number, endpointId: number, request: BatchRequest) {
+    const group = this.pendingByLimit.get(limit);
+    if (!group) return;
+    const list = group.get(endpointId);
+    if (!list) return;
+
+    const next = list.filter((item) => item !== request);
+    if (next.length > 0) {
+      group.set(endpointId, next);
+      return;
+    }
+
+    group.delete(endpointId);
+    if (group.size === 0) {
+      this.pendingByLimit.delete(limit);
+    }
+  }
+
+  private async flush() {
+    const snapshot = new Map(this.pendingByLimit);
+    this.pendingByLimit.clear();
+
+    try {
+      await Promise.all(
+        Array.from(snapshot.entries(), async ([limit, group]) => {
+          const endpointIds = Array.from(group.keys());
+          if (endpointIds.length === 0) return;
+
+          try {
+            const map = await fetchProbeLogsByEndpointIds(endpointIds, limit);
+            for (const [endpointId, requests] of group.entries()) {
+              const logs = map[endpointId] ?? [];
+              for (const req of requests) req.resolve(logs);
+            }
+          } catch (error) {
+            for (const requests of group.values()) {
+              for (const req of requests) req.reject(error);
+            }
+          }
+        })
+      );
+    } catch (error) {
+      for (const group of snapshot.values()) {
+        for (const requests of group.values()) {
+          for (const req of requests) req.reject(error);
+        }
+      }
+    }
+  }
+}
+
+export const probeLogsBatcher = new ProbeLogsBatcher();

+ 15 - 62
src/lib/provider-endpoints/probe-scheduler.ts

@@ -4,6 +4,7 @@ import {
   type LeaderLock,
   releaseLeaderLock,
   renewLeaderLock,
+  startLeaderLockKeepAlive,
 } from "@/lib/provider-endpoints/leader-lock";
 import { probeProviderEndpointAndRecordByEndpoint } from "@/lib/provider-endpoints/probe";
 import {
@@ -29,15 +30,8 @@ const SINGLE_VENDOR_INTERVAL_MS = 600_000;
 const TIMEOUT_OVERRIDE_INTERVAL_MS = 10_000;
 // Scheduler tick interval - use shortest possible interval to support timeout override
 const TICK_INTERVAL_MS = Math.min(BASE_INTERVAL_MS, TIMEOUT_OVERRIDE_INTERVAL_MS);
-// Max idle DB polling interval (default 30s, bounded by base interval)
-const DEFAULT_IDLE_DB_POLL_INTERVAL_MS = Math.min(BASE_INTERVAL_MS, 30_000);
-const IDLE_DB_POLL_INTERVAL_MS = Math.max(
-  1,
-  parseIntWithDefault(
-    process.env.ENDPOINT_PROBE_IDLE_DB_POLL_INTERVAL_MS,
-    DEFAULT_IDLE_DB_POLL_INTERVAL_MS
-  )
-);
+// Max idle DB polling interval (bounded by base interval)
+const IDLE_DB_POLL_INTERVAL_MS = Math.min(BASE_INTERVAL_MS, 30_000);
 const TIMEOUT_MS = Math.max(1, parseIntWithDefault(process.env.ENDPOINT_PROBE_TIMEOUT_MS, 5_000));
 const CONCURRENCY = Math.max(1, parseIntWithDefault(process.env.ENDPOINT_PROBE_CONCURRENCY, 10));
 const CYCLE_JITTER_MS = Math.max(
@@ -191,55 +185,6 @@ async function ensureLeaderLock(): Promise<boolean> {
   return true;
 }
 
-function startLeaderLockKeepAlive(onLost: () => void): () => void {
-  let stopped = false;
-  let renewing = false;
-  let intervalId: ReturnType<typeof setInterval> | undefined;
-
-  const stop = () => {
-    if (stopped) return;
-    stopped = true;
-    if (intervalId) clearInterval(intervalId);
-  };
-
-  const tick = async () => {
-    if (stopped || renewing) return;
-
-    const current = schedulerState.__CCH_ENDPOINT_PROBE_SCHEDULER_LOCK__;
-    if (!current) {
-      stop();
-      onLost();
-      return;
-    }
-
-    renewing = true;
-    try {
-      const ok = await renewLeaderLock(current, LOCK_TTL_MS);
-      if (!ok) {
-        schedulerState.__CCH_ENDPOINT_PROBE_SCHEDULER_LOCK__ = undefined;
-        stop();
-        onLost();
-        logger.warn("[EndpointProbeScheduler] Lost leader lock during probe cycle", {
-          key: current.key,
-          lockType: current.lockType,
-        });
-      }
-    } finally {
-      renewing = false;
-    }
-  };
-
-  const intervalMs = Math.max(1000, Math.floor(LOCK_TTL_MS / 2));
-  intervalId = setInterval(() => {
-    void tick();
-  }, intervalMs);
-
-  const timer = intervalId as unknown as { unref?: () => void };
-  timer.unref?.();
-
-  return stop;
-}
-
 async function runProbeCycle(): Promise<void> {
   if (schedulerState.__CCH_ENDPOINT_PROBE_SCHEDULER_RUNNING__) {
     return;
@@ -271,10 +216,18 @@ async function runProbeCycle(): Promise<void> {
       }
     }
 
-    stopKeepAlive = startLeaderLockKeepAlive(() => {
-      leadershipLost = true;
-      clearNextWorkHints();
-    });
+    stopKeepAlive = startLeaderLockKeepAlive({
+      getLock: () => schedulerState.__CCH_ENDPOINT_PROBE_SCHEDULER_LOCK__,
+      clearLock: () => {
+        schedulerState.__CCH_ENDPOINT_PROBE_SCHEDULER_LOCK__ = undefined;
+      },
+      ttlMs: LOCK_TTL_MS,
+      logTag: "EndpointProbeScheduler",
+      onLost: () => {
+        leadershipLost = true;
+        clearNextWorkHints();
+      },
+    }).stop;
 
     const jitter = CYCLE_JITTER_MS > 0 ? Math.floor(Math.random() * CYCLE_JITTER_MS) : 0;
     await sleep(jitter);

+ 57 - 0
src/repository/_shared/usage-log-filters.ts

@@ -0,0 +1,57 @@
+import type { SQL } from "drizzle-orm";
+import { eq, gte, lt, sql } from "drizzle-orm";
+import { messageRequest } from "@/drizzle/schema";
+
+export interface UsageLogFilterParams {
+  sessionId?: string;
+  startTime?: number;
+  endTime?: number;
+  statusCode?: number;
+  excludeStatusCode200?: boolean;
+  model?: string;
+  endpoint?: string;
+  minRetryCount?: number;
+}
+
+export function buildUsageLogConditions(filters: UsageLogFilterParams): SQL[] {
+  const conditions: SQL[] = [];
+
+  const trimmedSessionId = filters.sessionId?.trim();
+  if (trimmedSessionId) {
+    conditions.push(eq(messageRequest.sessionId, trimmedSessionId));
+  }
+
+  if (filters.startTime !== undefined) {
+    const startDate = new Date(filters.startTime);
+    conditions.push(gte(messageRequest.createdAt, startDate));
+  }
+
+  if (filters.endTime !== undefined) {
+    const endDate = new Date(filters.endTime);
+    conditions.push(lt(messageRequest.createdAt, endDate));
+  }
+
+  if (filters.statusCode !== undefined) {
+    conditions.push(eq(messageRequest.statusCode, filters.statusCode));
+  } else if (filters.excludeStatusCode200) {
+    conditions.push(
+      sql`(${messageRequest.statusCode} IS NULL OR ${messageRequest.statusCode} <> 200)`
+    );
+  }
+
+  if (filters.model) {
+    conditions.push(eq(messageRequest.model, filters.model));
+  }
+
+  if (filters.endpoint) {
+    conditions.push(eq(messageRequest.endpoint, filters.endpoint));
+  }
+
+  if (filters.minRetryCount !== undefined) {
+    conditions.push(
+      sql`GREATEST(COALESCE(jsonb_array_length(${messageRequest.providerChain}) - 1, 0), 0) >= ${filters.minRetryCount}`
+    );
+  }
+
+  return conditions;
+}

+ 2 - 2
src/repository/overview.ts

@@ -1,6 +1,6 @@
 "use server";
 
-import { and, avg, count, eq, gte, isNull, lt, lte, sql, sum } from "drizzle-orm";
+import { and, avg, count, eq, gte, isNull, lt, sql, sum } from "drizzle-orm";
 import { db } from "@/drizzle/db";
 import { messageRequest } from "@/drizzle/schema";
 import { Decimal, toCostDecimal } from "@/lib/utils/currency";
@@ -141,7 +141,7 @@ export async function getOverviewMetricsWithComparison(
           EXCLUDE_WARMUP_CONDITION,
           userCondition,
           gte(messageRequest.createdAt, yesterdayStart),
-          lte(messageRequest.createdAt, yesterdayEnd)
+          lt(messageRequest.createdAt, yesterdayEnd)
         )
       ),
 

+ 2 - 1
src/repository/provider-endpoints-batch.ts

@@ -76,7 +76,8 @@ export async function findProviderEndpointProbeLogsBatch(input: {
     return new Map();
   }
 
-  const limitPerEndpoint = Math.max(1, input.limitPerEndpoint);
+  const rawLimit = Number(input.limitPerEndpoint);
+  const limitPerEndpoint = Number.isFinite(rawLimit) ? Math.max(1, Math.trunc(rawLimit)) : 1;
 
   // 性能:避免 `ROW_NUMBER() OVER (PARTITION BY ...)` 在单个端点 logs 很多时退化为更重的扫描/排序。
   // 改为 LATERAL + LIMIT:每个 endpoint_id 仅取最新 N 条,能更好利用 (endpoint_id, created_at desc) 索引。

+ 3 - 2
src/repository/provider.ts

@@ -747,7 +747,7 @@ export async function deleteProvider(id: number): Promise<boolean> {
 
     const result = await tx
       .update(providers)
-      .set({ deletedAt: now })
+      .set({ deletedAt: now, updatedAt: now })
       .where(and(eq(providers.id, id), isNull(providers.deletedAt)))
       .returning({ id: providers.id });
 
@@ -1132,7 +1132,7 @@ export async function getProviderStatistics(): Promise<ProviderStatisticsRow[]>
       return await providerStatisticsInFlight.promise;
     }
 
-    const promise = (async () => {
+    const promise: Promise<ProviderStatisticsRow[]> = (async () => {
       // 使用 providerChain 最后一项的 providerId 来确定最终供应商(兼容重试切换)
       // 如果 provider_chain 为空(无重试),则使用 provider_id 字段
       const query = sql`
@@ -1221,6 +1221,7 @@ export async function getProviderStatistics(): Promise<ProviderStatisticsRow[]>
       return data;
     })();
 
+    // Set in-flight BEFORE awaiting to prevent concurrent callers from starting duplicate queries
     providerStatisticsInFlight = { timezone, promise };
 
     try {

+ 9 - 62
src/repository/statistics.ts

@@ -3,6 +3,7 @@ import "server-only";
 import { and, eq, gte, inArray, isNull, lt, sql } from "drizzle-orm";
 import { db } from "@/drizzle/db";
 import { keys, messageRequest } from "@/drizzle/schema";
+import { TTLMap } from "@/lib/cache/ttl-map";
 import { resolveSystemTimezone } from "@/lib/utils/timezone";
 import type {
   DatabaseKey,
@@ -17,29 +18,16 @@ import type {
 import { EXCLUDE_WARMUP_CONDITION } from "./_shared/message-request-conditions";
 
 /**
- * Key ID -> key 字符串缓存
+ * Key ID -> key string cache
  *
- * 背景:message_request.key 存储的是 key 字符串,但上层多以 keyId 传参;
- * 在配额检查/Redis 降级等高频路径中,重复查询 keys 表会放大 DB 压力。
- *
- * 说明:
- * - 短 TTL 允许轻微陈旧(key 一般不变)
- * - 简单 size 控制,避免在多租户场景无限增长
+ * Short TTL allows slight staleness (keys rarely change).
+ * Size-bounded to avoid unbounded growth in multi-tenant scenarios.
  */
-const KEY_STRING_BY_ID_CACHE_TTL_MS = 5 * 60 * 1000; // 5 分钟
-const KEY_STRING_BY_ID_CACHE_MAX_SIZE = 1000;
-const keyStringByIdCache = new Map<number, { key: string; expiresAt: number }>();
+const keyStringByIdCache = new TTLMap<number, string>({ ttlMs: 5 * 60 * 1000, maxSize: 1000 });
 
 async function getKeyStringByIdCached(keyId: number): Promise<string | null> {
-  const now = Date.now();
   const cached = keyStringByIdCache.get(keyId);
-  if (cached && cached.expiresAt > now) {
-    // LRU-like:刷新 TTL 并 bump 插入顺序(delete+set),让热点 key 不容易被淘汰。
-    cached.expiresAt = now + KEY_STRING_BY_ID_CACHE_TTL_MS;
-    keyStringByIdCache.delete(keyId);
-    keyStringByIdCache.set(keyId, cached);
-    return cached.key;
-  }
+  if (cached !== undefined) return cached;
 
   const keyRecord = await db
     .select({ key: keys.key })
@@ -48,35 +36,9 @@ async function getKeyStringByIdCached(keyId: number): Promise<string | null> {
     .limit(1);
 
   const keyString = keyRecord?.[0]?.key ?? null;
-  if (!keyString) {
-    keyStringByIdCache.delete(keyId);
-    return null;
-  }
-
-  // Size 控制:先清理过期;仍超限则淘汰最早的一小部分,避免一次性清空导致缓存击穿
-  if (keyStringByIdCache.size >= KEY_STRING_BY_ID_CACHE_MAX_SIZE) {
-    for (const [id, value] of keyStringByIdCache) {
-      if (value.expiresAt <= now) {
-        keyStringByIdCache.delete(id);
-      }
-    }
-
-    if (keyStringByIdCache.size >= KEY_STRING_BY_ID_CACHE_MAX_SIZE) {
-      const evictCount = Math.max(1, Math.ceil(KEY_STRING_BY_ID_CACHE_MAX_SIZE * 0.1));
-      let remaining = evictCount;
-
-      for (const id of keyStringByIdCache.keys()) {
-        keyStringByIdCache.delete(id);
-        remaining -= 1;
-        if (remaining <= 0) break;
-      }
-    }
-  }
+  if (!keyString) return null;
 
-  keyStringByIdCache.set(keyId, {
-    key: keyString,
-    expiresAt: now + KEY_STRING_BY_ID_CACHE_TTL_MS,
-  });
+  keyStringByIdCache.set(keyId, keyString);
   return keyString;
 }
 
@@ -833,21 +795,6 @@ export async function sumUserCostToday(userId: number): Promise<number> {
   return Number(row?.total_cost || 0);
 }
 
-/**
- * 查询 Key 历史总消费(通过 Key ID)
- * 用于显示 Key 的历史总消费统计
- * @param keyId - Key 的数据库 ID
- * @param maxAgeDays - 最大查询天数,默认 365 天(避免全表扫描)
- */
-export async function sumKeyTotalCostById(
-  keyId: number,
-  maxAgeDays: number = 365
-): Promise<number> {
-  const keyString = await getKeyStringByIdCached(keyId);
-  if (!keyString) return 0;
-  return sumKeyTotalCost(keyString, maxAgeDays);
-}
-
 /**
  * Query Key total cost (with optional time boundary)
  * @param keyHash - API Key hash
@@ -1060,7 +1007,7 @@ export interface QuotaCostRanges {
   rangeMonthly: { startTime: Date; endTime: Date };
 }
 
-export interface QuotaCostSummary {
+interface QuotaCostSummary {
   cost5h: number;
   costDaily: number;
   costWeekly: number;

+ 39 - 321
src/repository/usage-logs.ts

@@ -1,13 +1,15 @@
 import "server-only";
 
-import { and, desc, eq, gte, isNull, lt, sql } from "drizzle-orm";
+import { and, desc, eq, isNull, sql } from "drizzle-orm";
 import { db } from "@/drizzle/db";
 import { keys as keysTable, messageRequest, providers, users } from "@/drizzle/schema";
+import { TTLMap } from "@/lib/cache/ttl-map";
 import { buildUnifiedSpecialSettings } from "@/lib/utils/special-settings";
 import type { ProviderChainItem } from "@/types/message";
 import type { SpecialSetting } from "@/types/special-settings";
 import { escapeLike } from "./_shared/like";
 import { EXCLUDE_WARMUP_CONDITION } from "./_shared/message-request-conditions";
+import { buildUsageLogConditions } from "./_shared/usage-log-filters";
 
 export interface UsageLogFilters {
   userId?: number;
@@ -114,21 +116,7 @@ export interface UsageLogBatchFilters extends Omit<UsageLogFilters, "page" | "pa
 export async function findUsageLogsBatch(
   filters: UsageLogBatchFilters
 ): Promise<UsageLogsBatchResult> {
-  const {
-    userId,
-    keyId,
-    providerId,
-    sessionId,
-    startTime,
-    endTime,
-    statusCode,
-    excludeStatusCode200,
-    model,
-    endpoint,
-    minRetryCount,
-    cursor,
-    limit = 50,
-  } = filters;
+  const { userId, keyId, providerId, cursor, limit = 50 } = filters;
 
   // Build query conditions
   const conditions = [isNull(messageRequest.deletedAt)];
@@ -145,42 +133,7 @@ export async function findUsageLogsBatch(
     conditions.push(eq(messageRequest.providerId, providerId));
   }
 
-  const trimmedSessionId = sessionId?.trim();
-  if (trimmedSessionId) {
-    conditions.push(eq(messageRequest.sessionId, trimmedSessionId));
-  }
-
-  if (startTime !== undefined) {
-    const startDate = new Date(startTime);
-    conditions.push(gte(messageRequest.createdAt, startDate));
-  }
-
-  if (endTime !== undefined) {
-    const endDate = new Date(endTime);
-    conditions.push(lt(messageRequest.createdAt, endDate));
-  }
-
-  if (statusCode !== undefined) {
-    conditions.push(eq(messageRequest.statusCode, statusCode));
-  } else if (excludeStatusCode200) {
-    conditions.push(
-      sql`(${messageRequest.statusCode} IS NULL OR ${messageRequest.statusCode} <> 200)`
-    );
-  }
-
-  if (model) {
-    conditions.push(eq(messageRequest.model, model));
-  }
-
-  if (endpoint) {
-    conditions.push(eq(messageRequest.endpoint, endpoint));
-  }
-
-  if (minRetryCount !== undefined) {
-    conditions.push(
-      sql`GREATEST(COALESCE(jsonb_array_length(${messageRequest.providerChain}) - 1, 0), 0) >= ${minRetryCount}`
-    );
-  }
+  conditions.push(...buildUsageLogConditions(filters));
 
   // Cursor-based pagination: WHERE (created_at, id) < (cursor_created_at, cursor_id)
   // Using row value comparison for efficient keyset pagination
@@ -281,7 +234,7 @@ export async function findUsageLogsBatch(
   return { logs, nextCursor, hasMore };
 }
 
-export interface UsageLogSlimFilters {
+interface UsageLogSlimFilters {
   keyString: string;
   /** Session ID(精确匹配;空字符串/空白视为不筛选) */
   sessionId?: string;
@@ -300,7 +253,7 @@ export interface UsageLogSlimFilters {
   pageSize?: number;
 }
 
-export interface UsageLogSlimRow {
+interface UsageLogSlimRow {
   id: number;
   createdAt: Date | null;
   model: string | null;
@@ -318,71 +271,13 @@ export interface UsageLogSlimRow {
   cacheTtlApplied: string | null;
 }
 
-// my-usage logs:分页需要 totalPages,COUNT(*) 在大表上仍可能较重。
-// 这里对“相同筛选条件”的 total 做短 TTL 缓存,避免用户翻页/轮询时重复 COUNT。
-const USAGE_LOG_SLIM_TOTAL_CACHE_TTL_MS = 10 * 1000; // 10 秒
-const USAGE_LOG_SLIM_TOTAL_CACHE_MAX_SIZE = 1000;
-const usageLogSlimTotalCache = new Map<string, { total: number; expiresAt: number }>();
-
-function getUsageLogSlimTotalFromCache(key: string): number | null {
-  const now = Date.now();
-  const cached = usageLogSlimTotalCache.get(key);
-  if (!cached) return null;
-  if (cached.expiresAt <= now) {
-    usageLogSlimTotalCache.delete(key);
-    return null;
-  }
-
-  // LRU-like bump
-  usageLogSlimTotalCache.delete(key);
-  usageLogSlimTotalCache.set(key, cached);
-  return cached.total;
-}
-
-function setUsageLogSlimTotalToCache(key: string, total: number): void {
-  const now = Date.now();
-
-  if (usageLogSlimTotalCache.size >= USAGE_LOG_SLIM_TOTAL_CACHE_MAX_SIZE) {
-    for (const [k, v] of usageLogSlimTotalCache) {
-      if (v.expiresAt <= now) {
-        usageLogSlimTotalCache.delete(k);
-      }
-    }
-
-    if (usageLogSlimTotalCache.size >= USAGE_LOG_SLIM_TOTAL_CACHE_MAX_SIZE) {
-      const evictCount = Math.max(1, Math.ceil(USAGE_LOG_SLIM_TOTAL_CACHE_MAX_SIZE * 0.1));
-      let remaining = evictCount;
-
-      for (const k of usageLogSlimTotalCache.keys()) {
-        usageLogSlimTotalCache.delete(k);
-        remaining -= 1;
-        if (remaining <= 0) break;
-      }
-    }
-  }
-
-  usageLogSlimTotalCache.set(key, {
-    total,
-    expiresAt: now + USAGE_LOG_SLIM_TOTAL_CACHE_TTL_MS,
-  });
-}
+// my-usage logs: short TTL cache for total count to avoid repeated COUNT(*) on pagination/polling.
+const usageLogSlimTotalCache = new TTLMap<string, number>({ ttlMs: 10_000, maxSize: 1000 });
 
 export async function findUsageLogsForKeySlim(
   filters: UsageLogSlimFilters
 ): Promise<{ logs: UsageLogSlimRow[]; total: number }> {
-  const {
-    keyString,
-    sessionId,
-    startTime,
-    endTime,
-    statusCode,
-    excludeStatusCode200,
-    model,
-    endpoint,
-    minRetryCount,
-    page = 1,
-    pageSize = 50,
-  } = filters;
+  const { keyString, page = 1, pageSize = 50 } = filters;
 
   const safePage = page > 0 ? page : 1;
   const safePageSize = Math.min(100, Math.max(1, pageSize));
@@ -393,54 +288,19 @@ export async function findUsageLogsForKeySlim(
     EXCLUDE_WARMUP_CONDITION,
   ];
 
-  const trimmedSessionId = sessionId?.trim();
-  if (trimmedSessionId) {
-    conditions.push(eq(messageRequest.sessionId, trimmedSessionId));
-  }
-
   const totalCacheKey = [
     keyString,
-    trimmedSessionId ?? "",
-    startTime ?? "",
-    endTime ?? "",
-    statusCode ?? "",
-    excludeStatusCode200 ? "1" : "0",
-    model ?? "",
-    endpoint ?? "",
-    minRetryCount ?? "",
+    filters.sessionId?.trim() ?? "",
+    filters.startTime ?? "",
+    filters.endTime ?? "",
+    filters.statusCode ?? "",
+    filters.excludeStatusCode200 ? "1" : "0",
+    filters.model ?? "",
+    filters.endpoint ?? "",
+    filters.minRetryCount ?? "",
   ].join("\u0001");
 
-  if (startTime !== undefined) {
-    const startDate = new Date(startTime);
-    conditions.push(gte(messageRequest.createdAt, startDate));
-  }
-
-  if (endTime !== undefined) {
-    const endDate = new Date(endTime);
-    conditions.push(lt(messageRequest.createdAt, endDate));
-  }
-
-  if (statusCode !== undefined) {
-    conditions.push(eq(messageRequest.statusCode, statusCode));
-  } else if (excludeStatusCode200) {
-    conditions.push(
-      sql`(${messageRequest.statusCode} IS NULL OR ${messageRequest.statusCode} <> 200)`
-    );
-  }
-
-  if (model) {
-    conditions.push(eq(messageRequest.model, model));
-  }
-
-  if (endpoint) {
-    conditions.push(eq(messageRequest.endpoint, endpoint));
-  }
-
-  if (minRetryCount !== undefined) {
-    conditions.push(
-      sql`GREATEST(COALESCE(jsonb_array_length(${messageRequest.providerChain}) - 1, 0), 0) >= ${minRetryCount}`
-    );
-  }
+  conditions.push(...buildUsageLogConditions(filters));
 
   const offset = (safePage - 1) * safePageSize;
   const results = await db
@@ -472,8 +332,8 @@ export async function findUsageLogsForKeySlim(
 
   let total = offset + pageRows.length;
 
-  const cachedTotal = getUsageLogSlimTotalFromCache(totalCacheKey);
-  if (cachedTotal !== null) {
+  const cachedTotal = usageLogSlimTotalCache.get(totalCacheKey);
+  if (cachedTotal !== undefined) {
     total = Math.max(cachedTotal, total);
     return {
       logs: pageRows.map((row) => ({ ...row, costUsd: row.costUsd?.toString() ?? null })),
@@ -500,43 +360,18 @@ export async function findUsageLogsForKeySlim(
     costUsd: row.costUsd?.toString() ?? null,
   }));
 
-  setUsageLogSlimTotalToCache(totalCacheKey, total);
+  usageLogSlimTotalCache.set(totalCacheKey, total);
   return { logs, total };
 }
 
-const DISTINCT_KEY_OPTIONS_CACHE_TTL_MS = 5 * 60 * 1000; // 5 分钟
-const DISTINCT_KEY_OPTIONS_CACHE_MAX_SIZE = 200;
-
-const distinctModelsByKeyCache = new Map<string, { data: string[]; expiresAt: number }>();
-const distinctEndpointsByKeyCache = new Map<string, { data: string[]; expiresAt: number }>();
-
-function setDistinctKeyOptionsCache(
-  cache: Map<string, { data: string[]; expiresAt: number }>,
-  key: string,
-  data: string[]
-): void {
-  const now = Date.now();
-  if (cache.size >= DISTINCT_KEY_OPTIONS_CACHE_MAX_SIZE) {
-    for (const [k, v] of cache) {
-      if (v.expiresAt <= now) {
-        cache.delete(k);
-      }
-    }
-
-    if (cache.size >= DISTINCT_KEY_OPTIONS_CACHE_MAX_SIZE) {
-      const evictCount = Math.max(1, Math.ceil(DISTINCT_KEY_OPTIONS_CACHE_MAX_SIZE * 0.1));
-      let remaining = evictCount;
-
-      for (const k of cache.keys()) {
-        cache.delete(k);
-        remaining -= 1;
-        if (remaining <= 0) break;
-      }
-    }
-  }
-
-  cache.set(key, { data, expiresAt: now + DISTINCT_KEY_OPTIONS_CACHE_TTL_MS });
-}
+const distinctModelsByKeyCache = new TTLMap<string, string[]>({
+  ttlMs: 5 * 60 * 1000,
+  maxSize: 200,
+});
+const distinctEndpointsByKeyCache = new TTLMap<string, string[]>({
+  ttlMs: 5 * 60 * 1000,
+  maxSize: 200,
+});
 
 export async function getTotalUsageForKey(keyString: string): Promise<number> {
   const [row] = await db
@@ -554,15 +389,8 @@ export async function getTotalUsageForKey(keyString: string): Promise<number> {
 }
 
 export async function getDistinctModelsForKey(keyString: string): Promise<string[]> {
-  const now = Date.now();
   const cached = distinctModelsByKeyCache.get(keyString);
-  if (cached && cached.expiresAt > now) {
-    // LRU-like bump + sliding TTL
-    cached.expiresAt = now + DISTINCT_KEY_OPTIONS_CACHE_TTL_MS;
-    distinctModelsByKeyCache.delete(keyString);
-    distinctModelsByKeyCache.set(keyString, cached);
-    return cached.data;
-  }
+  if (cached !== undefined) return cached;
 
   const result = await db.execute(
     sql`select distinct ${messageRequest.model} as model
@@ -578,20 +406,13 @@ export async function getDistinctModelsForKey(keyString: string): Promise<string
     .map((row) => (row as { model?: string }).model)
     .filter((model): model is string => !!model && model.trim().length > 0);
 
-  setDistinctKeyOptionsCache(distinctModelsByKeyCache, keyString, models);
+  distinctModelsByKeyCache.set(keyString, models);
   return models;
 }
 
 export async function getDistinctEndpointsForKey(keyString: string): Promise<string[]> {
-  const now = Date.now();
   const cached = distinctEndpointsByKeyCache.get(keyString);
-  if (cached && cached.expiresAt > now) {
-    // LRU-like bump + sliding TTL
-    cached.expiresAt = now + DISTINCT_KEY_OPTIONS_CACHE_TTL_MS;
-    distinctEndpointsByKeyCache.delete(keyString);
-    distinctEndpointsByKeyCache.set(keyString, cached);
-    return cached.data;
-  }
+  if (cached !== undefined) return cached;
 
   const result = await db.execute(
     sql`select distinct ${messageRequest.endpoint} as endpoint
@@ -607,7 +428,7 @@ export async function getDistinctEndpointsForKey(keyString: string): Promise<str
     .map((row) => (row as { endpoint?: string }).endpoint)
     .filter((endpoint): endpoint is string => !!endpoint && endpoint.trim().length > 0);
 
-  setDistinctKeyOptionsCache(distinctEndpointsByKeyCache, keyString, endpoints);
+  distinctEndpointsByKeyCache.set(keyString, endpoints);
   return endpoints;
 }
 
@@ -616,26 +437,11 @@ export async function getDistinctEndpointsForKey(keyString: string): Promise<str
  */
 
 export async function findUsageLogsWithDetails(filters: UsageLogFilters): Promise<UsageLogsResult> {
-  const {
-    userId,
-    keyId,
-    providerId,
-    sessionId,
-    startTime,
-    endTime,
-    statusCode,
-    excludeStatusCode200,
-    model,
-    endpoint,
-    minRetryCount,
-    page = 1,
-    pageSize = 50,
-  } = filters;
+  const { userId, keyId, providerId, page = 1, pageSize = 50 } = filters;
 
   const safePage = page > 0 ? page : 1;
   const safePageSize = Math.min(200, Math.max(1, pageSize));
 
-  // 构建查询条件
   const conditions = [isNull(messageRequest.deletedAt)];
 
   if (userId !== undefined) {
@@ -650,47 +456,7 @@ export async function findUsageLogsWithDetails(filters: UsageLogFilters): Promis
     conditions.push(eq(messageRequest.providerId, providerId));
   }
 
-  const trimmedSessionId = sessionId?.trim();
-  if (trimmedSessionId) {
-    conditions.push(eq(messageRequest.sessionId, trimmedSessionId));
-  }
-
-  // 使用毫秒时间戳进行时间比较
-  // 前端传递的是浏览器本地时区的毫秒时间戳,直接与数据库的 timestamptz 比较
-  // PostgreSQL 会自动处理时区转换
-  if (startTime !== undefined) {
-    const startDate = new Date(startTime);
-    conditions.push(gte(messageRequest.createdAt, startDate));
-  }
-
-  if (endTime !== undefined) {
-    const endDate = new Date(endTime);
-    conditions.push(lt(messageRequest.createdAt, endDate));
-  }
-
-  if (statusCode !== undefined) {
-    conditions.push(eq(messageRequest.statusCode, statusCode));
-  } else if (excludeStatusCode200) {
-    // 包含 status_code 为空或非 200 的请求
-    conditions.push(
-      sql`(${messageRequest.statusCode} IS NULL OR ${messageRequest.statusCode} <> 200)`
-    );
-  }
-
-  if (model) {
-    conditions.push(eq(messageRequest.model, model));
-  }
-
-  if (endpoint) {
-    conditions.push(eq(messageRequest.endpoint, endpoint));
-  }
-
-  if (minRetryCount !== undefined) {
-    // 重试次数 = provider_chain 长度 - 1(最小为 0)
-    conditions.push(
-      sql`GREATEST(COALESCE(jsonb_array_length(${messageRequest.providerChain}) - 1, 0), 0) >= ${minRetryCount}`
-    );
-  }
+  conditions.push(...buildUsageLogConditions(filters));
 
   const offset = (safePage - 1) * safePageSize;
 
@@ -945,21 +711,8 @@ export async function findUsageLogSessionIdSuggestions(
 export async function findUsageLogsStats(
   filters: Omit<UsageLogFilters, "page" | "pageSize">
 ): Promise<UsageLogSummary> {
-  const {
-    userId,
-    keyId,
-    providerId,
-    sessionId,
-    startTime,
-    endTime,
-    statusCode,
-    excludeStatusCode200,
-    model,
-    endpoint,
-    minRetryCount,
-  } = filters;
-
-  // 构建查询条件(与 findUsageLogsWithDetails 相同)
+  const { userId, keyId, providerId } = filters;
+
   const conditions = [isNull(messageRequest.deletedAt)];
 
   if (userId !== undefined) {
@@ -974,42 +727,7 @@ export async function findUsageLogsStats(
     conditions.push(eq(messageRequest.providerId, providerId));
   }
 
-  const trimmedSessionId = sessionId?.trim();
-  if (trimmedSessionId) {
-    conditions.push(eq(messageRequest.sessionId, trimmedSessionId));
-  }
-
-  if (startTime !== undefined) {
-    const startDate = new Date(startTime);
-    conditions.push(gte(messageRequest.createdAt, startDate));
-  }
-
-  if (endTime !== undefined) {
-    const endDate = new Date(endTime);
-    conditions.push(lt(messageRequest.createdAt, endDate));
-  }
-
-  if (statusCode !== undefined) {
-    conditions.push(eq(messageRequest.statusCode, statusCode));
-  } else if (excludeStatusCode200) {
-    conditions.push(
-      sql`(${messageRequest.statusCode} IS NULL OR ${messageRequest.statusCode} <> 200)`
-    );
-  }
-
-  if (model) {
-    conditions.push(eq(messageRequest.model, model));
-  }
-
-  if (endpoint) {
-    conditions.push(eq(messageRequest.endpoint, endpoint));
-  }
-
-  if (minRetryCount !== undefined) {
-    conditions.push(
-      sql`GREATEST(COALESCE(jsonb_array_length(${messageRequest.providerChain}) - 1, 0), 0) >= ${minRetryCount}`
-    );
-  }
+  conditions.push(...buildUsageLogConditions(filters));
 
   const statsConditions = [...conditions, EXCLUDE_WARMUP_CONDITION];
 

+ 0 - 1
tests/unit/actions/my-usage-concurrent-inherit.test.ts

@@ -36,7 +36,6 @@ const statisticsMock = {
     costTotal: 0,
   })),
   sumKeyCostInTimeRange: vi.fn(async () => 0),
-  sumKeyTotalCostById: vi.fn(async () => 0),
   sumKeyQuotaCostsById: vi.fn(async () => ({
     cost5h: 0,
     costDaily: 0,

+ 2 - 5
tests/unit/actions/my-usage-consistency.test.ts

@@ -93,24 +93,21 @@ describe("my-usage getMyQuota data source consistency", () => {
 
     // Mock the statistics module
     const sumKeyCostInTimeRangeMock = vi.fn(async () => 10.5);
-    const sumKeyTotalCostByIdMock = vi.fn(async () => 100.25);
     const sumUserCostInTimeRangeMock = vi.fn(async () => 10.5);
     const sumUserTotalCostMock = vi.fn(async () => 100.25);
 
     vi.doMock("@/repository/statistics", () => ({
       sumKeyCostInTimeRange: sumKeyCostInTimeRangeMock,
-      sumKeyTotalCostById: sumKeyTotalCostByIdMock,
       sumUserCostInTimeRange: sumUserCostInTimeRangeMock,
       sumUserTotalCost: sumUserTotalCostMock,
     }));
 
     // Verify the function signatures match
     expect(typeof sumKeyCostInTimeRangeMock).toBe("function");
-    expect(typeof sumKeyTotalCostByIdMock).toBe("function");
 
     // The test validates that:
     // 1. Key 5h/daily/weekly/monthly uses sumKeyCostInTimeRange (DB direct)
-    // 2. Key total uses sumKeyTotalCostById (DB direct)
+    // 2. Key total uses sumKeyQuotaCostsById (DB direct)
     // 3. User 5h/weekly/monthly uses sumUserCost (which calls sumUserCostInTimeRange)
     // 4. User daily uses sumUserCostInTimeRange
     // 5. User total uses sumUserTotalCost
@@ -125,7 +122,7 @@ describe("my-usage getMyQuota data source consistency", () => {
     // Result: Inconsistent values when Redis cache differs from DB
 
     // After fix:
-    // - Key: sumKeyCostInTimeRange / sumKeyTotalCostById (DB direct)
+    // - Key: sumKeyCostInTimeRange / sumKeyQuotaCostsById (DB direct)
     // - User: sumUserCost / sumUserCostInTimeRange (DB direct)
     // Result: Consistent values from same data source
 

+ 0 - 43
tests/unit/lib/endpoint-circuit-breaker.test.ts

@@ -272,49 +272,6 @@ describe("endpoint-circuit-breaker", () => {
     expect(loadManyMock).toHaveBeenCalledTimes(1);
   });
 
-  test("getAllEndpointHealthStatusAsync: cache 超限时应淘汰最早的健康状态,避免内存无限增长", async () => {
-    vi.resetModules();
-
-    process.env.ENDPOINT_CIRCUIT_HEALTH_CACHE_MAX_SIZE = "3";
-
-    const loadManyMock = vi.fn(async (endpointIds: number[]) => {
-      const result = new Map<number, SavedEndpointCircuitState>();
-      for (const endpointId of endpointIds) {
-        result.set(endpointId, {
-          failureCount: 0,
-          lastFailureTime: null,
-          circuitState: "closed",
-          circuitOpenUntil: null,
-          halfOpenSuccessCount: 0,
-        });
-      }
-      return result;
-    });
-
-    vi.doMock("@/lib/logger", () => ({ logger: createLoggerMock() }));
-    vi.doMock("@/lib/redis/endpoint-circuit-breaker-state", () => ({
-      loadEndpointCircuitState: vi.fn(async () => null),
-      loadEndpointCircuitStates: loadManyMock,
-      saveEndpointCircuitState: vi.fn(async () => {}),
-      deleteEndpointCircuitState: vi.fn(async () => {}),
-    }));
-
-    vi.useFakeTimers();
-    vi.setSystemTime(new Date("2026-01-01T00:00:00.000Z"));
-
-    const { getAllEndpointHealthStatusAsync } = await import("@/lib/endpoint-circuit-breaker");
-
-    await getAllEndpointHealthStatusAsync([1, 2, 3], { forceRefresh: true });
-    expect(loadManyMock).toHaveBeenCalledTimes(1);
-
-    await getAllEndpointHealthStatusAsync([4], { forceRefresh: true });
-    expect(loadManyMock).toHaveBeenCalledTimes(2);
-
-    // 1 应已被淘汰;再次访问会触发一次新的 Redis 批量读取
-    await getAllEndpointHealthStatusAsync([1]);
-    expect(loadManyMock).toHaveBeenCalledTimes(3);
-  });
-
   test("triggerEndpointCircuitBreakerAlert should call sendCircuitBreakerAlert", async () => {
     vi.resetModules();
 

+ 1 - 0
tests/unit/lib/provider-endpoints/probe-scheduler.test.ts

@@ -54,6 +54,7 @@ vi.mock("@/lib/provider-endpoints/leader-lock", () => ({
   acquireLeaderLock: (...args: unknown[]) => acquireLeaderLockMock(...args),
   renewLeaderLock: (...args: unknown[]) => renewLeaderLockMock(...args),
   releaseLeaderLock: (...args: unknown[]) => releaseLeaderLockMock(...args),
+  startLeaderLockKeepAlive: () => ({ stop: () => {} }),
 }));
 
 vi.mock("@/repository", () => ({

+ 108 - 0
tests/unit/lib/ttl-map.test.ts

@@ -0,0 +1,108 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { TTLMap } from "@/lib/cache/ttl-map";
+
+describe("TTLMap", () => {
+  beforeEach(() => {
+    vi.useFakeTimers();
+  });
+
+  afterEach(() => {
+    vi.useRealTimers();
+  });
+
+  it("should return undefined for missing key", () => {
+    const map = new TTLMap<string, number>({ ttlMs: 1000, maxSize: 10 });
+    expect(map.get("missing")).toBeUndefined();
+  });
+
+  it("should store and retrieve a value", () => {
+    const map = new TTLMap<string, number>({ ttlMs: 1000, maxSize: 10 });
+    map.set("a", 42);
+    expect(map.get("a")).toBe(42);
+    expect(map.size).toBe(1);
+  });
+
+  it("should return undefined for expired key", () => {
+    const map = new TTLMap<string, number>({ ttlMs: 1000, maxSize: 10 });
+    map.set("a", 42);
+    vi.advanceTimersByTime(1001);
+    expect(map.get("a")).toBeUndefined();
+  });
+
+  it("should not return expired key via has()", () => {
+    const map = new TTLMap<string, number>({ ttlMs: 1000, maxSize: 10 });
+    map.set("a", 42);
+    vi.advanceTimersByTime(1001);
+    expect(map.has("a")).toBe(false);
+  });
+
+  it("should bump LRU order on get", () => {
+    const map = new TTLMap<string, number>({ ttlMs: 10000, maxSize: 3 });
+    map.set("a", 1);
+    map.set("b", 2);
+    map.set("c", 3);
+
+    // Access "a" to bump it (it was oldest)
+    map.get("a");
+
+    // Insert "d" - should evict "b" (oldest after bump), not "a"
+    map.set("d", 4);
+    expect(map.has("a")).toBe(true);
+    expect(map.has("b")).toBe(false);
+    expect(map.has("c")).toBe(true);
+    expect(map.has("d")).toBe(true);
+  });
+
+  it("should evict expired entries first when at capacity", () => {
+    const map = new TTLMap<string, number>({ ttlMs: 1000, maxSize: 3 });
+    map.set("a", 1);
+    map.set("b", 2);
+    map.set("c", 3);
+
+    // Expire all entries
+    vi.advanceTimersByTime(1001);
+
+    // Should evict expired entries, making room
+    map.set("d", 4);
+    expect(map.size).toBe(1);
+    expect(map.get("d")).toBe(4);
+  });
+
+  it("should evict oldest 10% when at capacity with no expired entries", () => {
+    const map = new TTLMap<string, number>({ ttlMs: 100000, maxSize: 10 });
+    for (let i = 0; i < 10; i++) {
+      map.set(`key-${i}`, i);
+    }
+    expect(map.size).toBe(10);
+
+    // Insert one more - should evict at least 1 (10% of 10 = 1)
+    map.set("new", 99);
+    expect(map.size).toBeLessThanOrEqual(10);
+    expect(map.get("new")).toBe(99);
+    // Oldest key should be evicted
+    expect(map.has("key-0")).toBe(false);
+  });
+
+  it("should delete an existing key", () => {
+    const map = new TTLMap<string, number>({ ttlMs: 1000, maxSize: 10 });
+    map.set("a", 1);
+    expect(map.delete("a")).toBe(true);
+    expect(map.get("a")).toBeUndefined();
+    expect(map.size).toBe(0);
+  });
+
+  it("should return false when deleting non-existent key", () => {
+    const map = new TTLMap<string, number>({ ttlMs: 1000, maxSize: 10 });
+    expect(map.delete("missing")).toBe(false);
+  });
+
+  it("should update existing key with new value and reset TTL", () => {
+    const map = new TTLMap<string, number>({ ttlMs: 1000, maxSize: 10 });
+    map.set("a", 1);
+    vi.advanceTimersByTime(800);
+    map.set("a", 2);
+    vi.advanceTimersByTime(800);
+    // Should still be alive (TTL was reset on second set)
+    expect(map.get("a")).toBe(2);
+  });
+});