Skip to content

fix(void): load SQL helpers before the schema in void/db - #526

Merged
Brooooooklyn merged 1 commit into
mainfrom
fix/db-schema-cycle
Oct 21, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
fix/db-schema-cycle

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Fixes #472

Problem

db/schema.ts re-exports a table file from outside db/, and that file uses sql from void/db at the top level:

route ──▶ void/db ──▶ db/schema.ts ──▶ src/.../projects.schema.ts ──▶ void/db (still loading)
                                                                         sql = undefined ✗

In dev this throws __vite_ssr_import_0__.sql is not a function. #504 fixed the db/schema/ folder. Files anywhere else still hit the error.

Fix

Vite SSR runs imports in the order they are written. void/db now re-exports the drizzle-orm helpers (sql, eq, …) first, before it imports the schema. This applies to all three dialects (SQLite, PostgreSQL, MySQL).

void/db
  1. export { sql, eq, ... } from drizzle-orm   ← ready now
  2. driver, env
  3. import * as schema ──▶ projects.schema.ts ──▶ void/db.sql ✓
  • The fix works wherever the schema file lives. It needs no import-graph tracking.
  • resolveId, virtual:void-db-schema and db/schema/** are unchanged.
  • Build output already linked sql directly. It still works, and it ships the same modules in a different order.
  • Still not supported: reading db at the top level of a schema file. It needs a request anyway.

Tests

Test main this PR
plugin-drizzle.test.ts: helper export comes first (sqlite/postgresql/mysql) ✗ ✓
plugin-vite-environment.test.ts: real dev server, #472 layout, route imports db before @schema ✗ sql is not a function ✓

Both files pass (103/103). Lint, format and the void typecheck are clean.

🤖 Generated with Claude Code

A table file that db/schema.ts re-exports from outside db/ (for example
src/resources/projects/projects.schema.ts) imports `sql` from void/db.
When a route loaded void/db first, the cycle

  void/db -> db/schema.ts -> projects.schema.ts -> void/db

handed the table file a half-loaded void/db, and `sql` was undefined in
dev ("__vite_ssr_import_0__.sql is not a function").

Vite SSR runs imports in source order, so void/db now re-exports the
drizzle-orm helpers before it imports the schema, for SQLite, PostgreSQL
and MySQL. The helpers are ready whatever path the schema file lives at.
Build output already linked the helpers directly and keeps working.

Fixes #472

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Brooooooklyn

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T05:27:39.069021Z b8f3efd Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-db-schema-cycle-void-cloud.voidzero-docs.workers.dev (commit b8f3efd)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://d1d6c59b-void-cloud.voidzero-docs.workers.dev b8f3efd 2026-10-21T05:27:02.178Z Visit the dashboard ↗

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: b8f3efdc31

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Brooooooklyn
Brooooooklyn merged commit b914330 into main Oct 21, 2026
20 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/db-schema-cycle branch October 21, 2026 06:49
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.

void/db imported from schema files outside db/schema.ts causes a circular import (sql is not a function)

1 participant