refactor(db): move MVP runtime queries to Drizzle + introspection check#17
Conversation
…ction check Split the 1.8k-line packages/db/src/index.ts into a barrel plus typed Drizzle query modules (artifacts, upload-sessions, api-keys, operation-events, workspaces) and a PostgresRepository / LocalRepository pair so MVP routes run through Drizzle query objects instead of ad-hoc raw SQL. The SqlExecutor surface is preserved for callers that still need it; PostgresRepository now requires a bound Drizzle instance and refuses to construct from a raw executor. Add packages/db/snapshot/schema.sql plus packages/db/scripts/introspect-check.mjs, which runs drizzle-kit export and exits 1 on drift versus the snapshot. Wire db:check into turbo.json and pnpm verify so schema drift fails CI. Also addresses CodeRabbit triage on the refactor: - upload-sessions.insert: avoid Invalid Date when put_url_expires_at is missing; fall back to new Date() since the column is notNull. - artifacts.updateExpiry: set updatedAt to the modification time, not the expiry timestamp. - local-repository.finalizeUploadSession: use the same 3-part path:objectKey:size key as PostgresRepository so the two backends agree on upload_incomplete detection. - agent-view: percent-encode path segments and trim trailing slashes on base URLs to avoid malformed view URLs. - types.ApiActor.scopes: narrow to ApiKey.scopes' union. - postgres/drizzle: extract DEFAULT_POSTGRES_OPTIONS shared with the executor; document the deliberate asymmetry between the two transaction signatures. - introspect-check: normalize CRLF before diffing the snapshot. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughThis PR modularizes packages/db: adds typed Drizzle query modules, Postgres/Hyperdrive/HTTP SqlExecutors, a Drizzle connection wrapper, and both PostgresRepository and LocalRepository implementations. It introduces API-key utilities, ID helpers, validation and transform utilities, and agent-view builders. A schema snapshot (packages/db/snapshot/schema.sql) and a CLI (scripts/introspect-check.mjs) provide runtime introspection and drift detection; CI/Turbo tasks and root/package scripts are updated to run db checks. Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Removes the duplicate root implementation that ran the script with inputs unmoored from packages/contracts, causing turbo to invalidate on every run and CodeRabbit to flag the wrong inputs glob in turbo.json.
|
agent-paste PR preview resources were cleaned up. The pr-preview-${context.issue.number} environment is left in place; remove it from the GitHub UI if desired. |
Summary
Backlog item #4 (now closed). Moves MVP workspace, api-key, upload-session, and artifact reads + writes onto Drizzle query objects under
packages/db/src/queries/*. KeepsrunCommandidempotency wrapper around mutations. Admin/cleanup set-based statements remain raw SQL.Adds
pnpm db:check(introspection guard): exports the current Drizzle schema viadrizzle-kitand diffs against the committedpackages/db/snapshot/schema.sql. Wired intopnpm verify.Done
packages/db/src/queries/{workspaces,api-keys,upload-sessions,artifacts,operation-events}.ts).PostgresRepositorybinds a Drizzle instance to eachSqlExecutorvia WeakMap so command handlers recover the typed client mid-transaction.packages/db/scripts/introspect-check.mjs+packages/db/snapshot/schema.sqlenforce schema = code.pnpm verifyrunsdb:check; forced-drift smoke confirms exit 1 on mutation, 0 on revert.pnpm verifygreen (61 Turbo tasks).Test plan
pnpm verify— 61/61Summary by CodeRabbit
New Features
Documentation
Chores