Conversation
Introduces 0062_add_llm_trajectories_table.sql so the table exists in databases that only apply SQL migrations; journal entry aligns with Drizzle tracking. Made-with: Cursor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a new Postgres migration so environments that apply raw SQL migrations (and rely on Drizzle’s migration journal) create the llm_trajectories table used for storing LLM call prompt/response trajectories and related metrics.
Changes:
- Add
0062_add_llm_trajectories_table.sqlto createllm_trajectories, its indexes, and foreign keys. - Update
packages/db/migrations/meta/_journal.jsonto register migration0062_add_llm_trajectories_tablefor Drizzle tracking.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/db/migrations/meta/_journal.json | Registers the new 0062 migration in Drizzle’s journal so it is tracked/applied in order. |
| packages/db/migrations/0062_add_llm_trajectories_table.sql | Creates the llm_trajectories table with indexes and FK constraints to organizations, users, and api_keys. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
PR Review: Add migration for llm_trajectories table The migration is well-structured overall — uses IF NOT EXISTS guards, DO blocks for idempotent FK constraints, and the SQL matches the Drizzle schema file. A few issues worth addressing: Bugs / Data Integrity 1. _journal.json loses its trailing newline The PR removes the final newline from _journal.json. This can cause noisy diffs and may break POSIX-compliant tooling. The trailing newline should be preserved. 2. Derived columns without CHECK constraints
ALTER TABLE "llm_trajectories"
ADD CONSTRAINT "chk_total_tokens" CHECK ("total_tokens" = "input_tokens" + "output_tokens");
ALTER TABLE "llm_trajectories"
ADD CONSTRAINT "chk_total_cost" CHECK ("total_cost" = "input_cost" + "output_cost");If totals are always computed server-side and never caller-supplied, consider dropping the derived columns in favour of generated columns or a view instead. 3. If CREATE UNIQUE INDEX IF NOT EXISTS "llm_trajectories_request_id_idx"
ON "llm_trajectories" ("request_id")
WHERE "request_id" IS NOT NULL;Performance 4. No index on Indexes cover org+created, org+model, purpose, and org+purpose+created — but not CREATE INDEX IF NOT EXISTS "llm_trajectories_user_id_idx" ON "llm_trajectories" ("user_id");5. Unbounded TEXT columns for prompt content
Security 6. Sensitive data stored in plaintext This table will hold raw system prompts and user conversations for every LLM call — potentially including confidential business logic (system prompts) and user PII. Recommend: row-level security scoped to Process 7. Schema file pre-dates the migration Per CLAUDE.md, schema + migration should be committed together. Summary
The migration will apply cleanly and the SQL matches the Drizzle schema, so nothing will break. The derived-column consistency and missing indexes are the most important fixes before this table sees production traffic. |
Introduces 0062_add_llm_trajectories_table.sql so the table exists in databases that only apply SQL migrations; journal entry aligns with Drizzle tracking.
Made-with: Cursor
Note
Medium Risk
Introduces a new database table with indexes and foreign keys; main risk is migration/runtime impact on large databases and potential downstream reliance on the new schema.
Overview
Adds SQL migration
0062_add_llm_trajectories_table.sqlto create a newllm_trajectoriestable for storing LLM request/response text, token/cost accounting, latency, success/error state, and JSON metadata.The migration also adds several query indexes and foreign key constraints to
organizations(cascade delete),users, andapi_keys(set null), and updates Drizzle’s migrations journal (meta/_journal.json) to register migration0062_add_llm_trajectories_table.Reviewed by Cursor Bugbot for commit 0f203f7. Bugbot is set up for automated code reviews on this repo. Configure here.