Skip to content

refactor(db): move MVP runtime queries to Drizzle + introspection check#17

Merged
isuttell merged 3 commits into
mainfrom
agents/drizzle
May 22, 2026
Merged

refactor(db): move MVP runtime queries to Drizzle + introspection check#17
isuttell merged 3 commits into
mainfrom
agents/drizzle

Conversation

@isuttell

@isuttell isuttell commented May 22, 2026

Copy link
Copy Markdown
Contributor

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/*. Keeps runCommand idempotency wrapper around mutations. Admin/cleanup set-based statements remain raw SQL.

Adds pnpm db:check (introspection guard): exports the current Drizzle schema via drizzle-kit and diffs against the committed packages/db/snapshot/schema.sql. Wired into pnpm verify.

Done

  • MVP queries route through Drizzle (packages/db/src/queries/{workspaces,api-keys,upload-sessions,artifacts,operation-events}.ts).
  • PostgresRepository binds a Drizzle instance to each SqlExecutor via WeakMap so command handlers recover the typed client mid-transaction.
  • packages/db/scripts/introspect-check.mjs + packages/db/snapshot/schema.sql enforce schema = code.
  • pnpm verify runs db:check; forced-drift smoke confirms exit 1 on mutation, 0 on revert.
  • pnpm verify green (61 Turbo tasks).

Test plan

  • pnpm verify — 61/61
  • Hosted smoke against PR preview (gated on Neon quota)

Summary by CodeRabbit

  • New Features

    • Added runtime DB schema integrity check and improved upload/session validation to reduce deployment drift and upload errors.
    • Enhanced artifact publish & agent view handling plus API key lifecycle support for previews and production.
  • Documentation

    • Updated project status with MVP progress, ADR coverage, deploy order, and next-step backlog.
  • Chores

    • Modularized database layer and added multiple execution backends with improved transaction/cleanup behaviors.

Review Change Stack

isuttell and others added 2 commits May 21, 2026 23:07
…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>
@isuttell isuttell temporarily deployed to pr-preview-17 May 22, 2026 06:26 — with GitHub Actions Inactive
@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3163d474-cc0c-4109-b4de-f2387c248fa8

📥 Commits

Reviewing files that changed from the base of the PR and between d34bd64 and 799c6a7.

📒 Files selected for processing (1)
  • package.json

Walkthrough

This 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

  • zaks-io/agent-paste#15: Adds openapi:check Turbo task and OpenAPI generation tooling; related to this PR's CI/script task changes for golden/check workflows.

"🐰 I hopped through schema and code,
Drizzle streams and queries sowed,
Snapshots checked, idents spun,
Local and Postgres both now run,
A tiny hop — a big deploy!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring the database layer to move MVP runtime queries to Drizzle ORM and adding an introspection check mechanism.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agents/drizzle

Comment @coderabbitai help to get the list of available commands and usage tips.

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.
@isuttell isuttell temporarily deployed to pr-preview-17 May 22, 2026 06:28 — with GitHub Actions Inactive
@isuttell isuttell merged commit 9861e70 into main May 22, 2026
2 of 3 checks passed
@isuttell isuttell deleted the agents/drizzle branch May 22, 2026 06:30
@github-actions

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant