Database
SkillDatabases & dataLets your agent query and modify the LLM Gateway database using SQL and its schema files.
Available today. Use it from your connected AI after setup.
No other account needed.
Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.
Then ask your AI: use the Database skill
About this skill
Query and change the LLM Gateway Postgres schema with Drizzle, reads, raw SQL, analytics and usage queries, the log table versus the hourly aggregation tables, used_model ids, cost sums, cached queries, and new columns. Use when editing packages/db/src/schema.ts, writing Drizzle or raw SQL, buildin
What this skill tells your AI
The instructions your AI receives, as published by theopenco/llmgateway in .agents/skills/database/SKILL.md and read by ahel’s review.
Run commands from the repository root.
pnpm push— push the schema to the dev (pnpm push-dev) and test (pnpm push-test) databases.pnpm seed— seed data.pnpm run setup— reset, push, and seed (use thelocal-stackskill first).
Schema changes
Edit packages/db/src/schema.ts, then use the migrations skill. Refresh local
state with pnpm run setup. Production applies migrations before rolling out
new images, so new code may rely on new columns and backfills at startup.
A new organization column goes into SerializedOrganization's Omit list
(packages/db/src/types.ts) when internal, or into the /orgs response schemas
when the dashboard shows it; apps/ui derives its type from it. Confirm with a
full pnpm build.
Queries
- Use Drizzle's object syntax; reads via
db().query.<table>.findMany()/findFirst(). - Columns are camelCase in TypeScript and snake_case in the database (
casing: "snake_case"); raw SQL usesuser_id, notuserId. - Usage and analytics read the hourly aggregation tables:
project_hourly_stats,project_hourly_model_stats(addsused_model/used_provider),project_hourly_source_stats(addssource),api_key_hourly_stats,api_key_hourly_model_stats,global_model_stats,global_source_stats. Joinproject→organizationfor org fields such asbilling_email. Querylogonly for data no aggregate holds (payloads,request_idlookups, individual finish reasons), and say why. logis per-request volume. Retention nulls its payload columns; rows and token/cost columns remain.- The gateway request path reads no
logrows at all; hot-path signals come from Redis counters maintained on the write path or small cached rows. used_modelstoresprovider/model[:region]. Compare with catalogue ids aftersplit_part(split_part(used_model, '/', 2), ':', 1)(as instats-calculator.ts), and use the same shape in seeds and fixtures.- Cost columns are
real, andSUM(real)accumulates in float4. Sum asSUM(CAST(col AS DOUBLE PRECISION)); for exact readsSUM(CAST(CAST(col AS DOUBLE PRECISION) AS NUMERIC)).real::numericrounds to 6 digits. - Coordinate settings updates by validating state at each write boundary; advisory locks such as
pg_advisory_xact_lockare not used.
Cached client
The cached client stores positional driver rows. Cache keys are namespaced by
SCHEMA_CACHE_VERSION (derived from schema.ts) and runMigrations clears
them, so a column change needs no manual bump.
Signals
- GitHub stars
- 2k
- Forks
- 190
- Last commit
- Sep 2026
Advanced
- Item type
- skill
- Key
database-theopenco- Source
- github.com/theopenco/llmgateway