POC Upgrade to Drizzle v1: Refactor Drizzle relations to separate files and update imports#2954
POC Upgrade to Drizzle v1: Refactor Drizzle relations to separate files and update imports#2954amikofalvy wants to merge 2 commits intomainfrom
Conversation
…drizzle-zod v1 RC (beta.14)
Major changes:
- Update drizzle-orm, drizzle-kit, drizzle-zod to v1 beta versions
- Convert all db.query.TABLE.findFirst/findMany (RQB) calls to db.select().from(TABLE) queries
to work around RQB v2 SQL aliasing bug with RAW where clauses
- Migrate drizzle-kit migration folder format from v2 (flat) to v3 (timestamped directories)
- Add defineRelations() for manage and runtime schemas (RQB v2 API)
- Fix drizzle-zod type inference issues with JSONB columns ($strip type, array double-wrapping)
- Update drizzle() call signature to use { client, schema, relations } format
- Update all mock-based unit tests to use db.select() chain mocks
- Fix boolean existence checks to use !! instead of !== null for undefined returns
https://claude.ai/code/session_01Awoa5fXq4jK2D7vcUhRw6n
Update drizzle() call to use { client, schema, relations } format and
import manageRelations for RQB v2 compatibility.
https://claude.ai/code/session_01Awoa5fXq4jK2D7vcUhRw6n
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
TL;DR — Upgrades Key changes
Summary | 275 files | 2 commits | base: Drizzle v1 RC dependency upgrade
All three Drizzle packages are pinned to exact v1 RC versions (no caret ranges) across four
Relation definitions extracted to dedicated files
The new
Database client initialization migrated to v1 API
All four production clients, both test clients, three
Data-access layer rewritten from
|
There was a problem hiding this comment.
This PR is misleadingly titled. It is not just a "Refactor Drizzle relations to separate files" — it is a Drizzle ORM v1 upgrade (^0.44.4 to 1.0.0-beta.20, drizzle-kit ^0.31.6 to 1.0.0-beta.20, drizzle-zod ^0.8.2 to 1.0.0-beta.14). This is a major dependency upgrade to a beta prerelease that touches the entire data-access layer.
High-severity concerns
-
Beta dependency in production — Pinning to
[email protected]introduces prerelease dependencies. This needs explicit team acknowledgment. -
Internal import path
drizzle-orm/_relations— Three files (manage-schema.ts:1,runtime-schema.ts:2,auth-schema.ts:1) import fromdrizzle-orm/_relations, an underscore-prefixed internal path not part of Drizzle's public API. -
Dual relation definitions — Relations are defined twice: via the old
relations()API still inmanage-schema.ts(lines 974-1394) /runtime-schema.ts(lines 701-1008), and via the newdefineRelations()in the new relation files. The old definitions should be removed or the duplication documented. -
Massive unrelated changes — 11 changeset files (seat limits, model fallback, cost breadcrumbs, anonymous sessions, etc.), CHANGELOG entries, CI workflow changes, CLI/UI changes, biome config, turbo config — none related to Drizzle. Should be split out or branch rebased.
-
All migration snapshots regenerated —
drizzle/*/meta/directories deleted and replaced with drizzle-kit v1 format. Needs careful validation. -
No changeset for the Drizzle upgrade — AGENTS.md mandates changesets for runtime behavior changes.
-
Dead
db.queryguard inagents.ts:786—if (!db.query?.projects?.findFirst)guards code now usingdb.select().from(). In Drizzle 1.0,db.querymay be absent, silently skippingstopWheninheritance and tool/function loading.
Medium-severity concerns
pnpm-lock.yamllikely regenerated — 1310 insertions / 408 deletions.- Version rollback —
agents-corefrom0.64.0to0.63.3, suggesting branch is based on older state.
Assessment
The db.query.* → db.select().from() conversions are mechanically correct. However, this PR should be split: the Drizzle upgrade deserves its own focused PR with proper changesets, clean migration verification, and no unrelated changes.
Claude Opus | 𝕏
| const requestDb = drizzle({ | ||
| client: connection, | ||
| schema, | ||
| relations: manageRelations, |
There was a problem hiding this comment.
The relations: manageRelations param here and the import at line 9 are the new Drizzle v1 pattern. The PR description doesn't mention this is a Drizzle v1 upgrade — please update the title/description to reflect the actual scope.
| "axios": "^1.13.5", | ||
| "cron-parser": "^5.5.0", | ||
| "drizzle-orm": "^0.44.4", | ||
| "drizzle-orm": "1.0.0-beta.20", |
There was a problem hiding this comment.
Pinning to [email protected] (a beta prerelease) in production is a significant risk. Has the team explicitly signed off on this?
Ito Test Report ✅17 test cases ran. 3 additional findings, 14 passed. Overall, 14 of 17 test cases passed in local regression coverage, confirming stable project/agent/external-agent/skills/datasets/evaluations routing under refresh and back/forward navigation, safe malformed-ID handling and recovery, authorization/XSS protections, idempotent rapid-save/create behavior, concurrent-tab convergence, mobile CRUD operability, and scheduled-trigger views with nullable conversation data. The three high-severity failures identified two real production regressions: playground chat thread continuity breaks after refresh because conversation IDs are regenerated instead of persisted, and ✅ Passed (14)ℹ️ Additional Findings (3)
|
Summary
This PR refactors the Drizzle ORM relations definitions by extracting them from schema files into dedicated relation files, and updates all imports throughout the codebase to use the new structure. This improves code organization and maintainability by separating schema definitions from their relations.
Key Changes
Created new relation files:
packages/agents-core/src/db/manage/manage-relations.ts- Contains all manage database relationspackages/agents-core/src/db/runtime/runtime-relations.ts- Contains all runtime database relationsUpdated schema files:
relationsimport frommanage-schema.tsandruntime-schema.tsUpdated database client files:
manage-client.ts- Now imports relations frommanage-relations.tsruntime-client.ts- Now imports relations fromruntime-relations.tstest-manage-client.ts- Updated to import from new relation filetest-runtime-client.ts- Updated to import from new relation fileUpdated data access layer:
defineRelationswhere neededUpdated package exports:
package.json- Added exports for the new relation files to maintain public API compatibilityUpdated other files:
dolt/ref-scope.ts- Updated to import relations from new locationagents-api/src/middleware/branchScopedDb.ts- Updated to import manage relationsauth-schema.ts- Updated relation import pathImplementation Details
The refactoring maintains backward compatibility by exporting the relation definitions through the package's public API. All database clients now explicitly import and register relations from their dedicated files, ensuring proper Drizzle ORM functionality while improving code organization.
https://claude.ai/code/session_01Awoa5fXq4jK2D7vcUhRw6n