Skip to content

cold-start: split Neon and pg database drivers#44

Merged
x0ba merged 1 commit into
stagingfrom
cold-start/split-db-drivers
May 28, 2026
Merged

cold-start: split Neon and pg database drivers#44
x0ba merged 1 commit into
stagingfrom
cold-start/split-db-drivers

Conversation

@x0ba
Copy link
Copy Markdown
Owner

@x0ba x0ba commented May 28, 2026

Stack Context

This stack reduces Vercel cold-start time by shrinking the shared SvelteKit server boot path and isolating heavy agent/GitHub dependencies.

Why?

The database module imported both Neon HTTP and pg drivers at startup. Production on Vercel only needs Neon, but still parsed the local Postgres stack on every cold boot.

Test plan

  • Confirm Vercel deployment connects to Neon
  • Confirm local dev still works against Docker Postgres

@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flightlog Ready Ready Preview, Comment May 28, 2026 4:56pm

Copy link
Copy Markdown
Owner Author

x0ba commented May 28, 2026

@x0ba x0ba changed the title Load Neon and pg database drivers through separate modules. cold-start: split Neon and pg database drivers May 28, 2026
@x0ba x0ba marked this pull request as ready for review May 28, 2026 07:56
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 28, 2026

Greptile Summary

This PR reduces Vercel cold-start latency by splitting the single database module into two lazily-loaded modules — one for the Neon HTTP driver (production) and one for node-postgres (local Docker). The module entry point uses top-level await import() to load only the relevant driver at runtime, which is valid given the project's ESM configuration ("type": "module").

  • index.ts replaces the eager dual-import with a conditional await import() ternary, ensuring only one driver module is parsed and evaluated per cold start.
  • local.ts and neon.ts each encapsulate a single driver's initialization logic, keeping the bundle for each environment clean.

Confidence Score: 5/5

Safe to merge — the refactor is a clean mechanical split with no behavioral changes on either the Vercel or local path.

The top-level await import() pattern is valid in this ESM project, the URL routing logic is unchanged, and each new file does exactly what the corresponding branch of the old createDatabase function did. No logic was altered.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/server/db/index.ts Refactored to use top-level await import() to lazily load only the needed DB driver; valid ESM pattern given "type": "module" in the project.
src/lib/server/db/local.ts New file isolating the pg/node-postgres driver; exports an unused LocalDatabase type alias that mirrors AppDatabase.
src/lib/server/db/neon.ts New file isolating the Neon HTTP driver; retains the pre-existing as unknown as NodePgDatabase cast to satisfy the shared AppDatabase type.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[index.ts module evaluation] --> B{isLocalDatabaseUrl?}
    B -- yes --> C["await import('./local')"]
    B -- no --> D["await import('./neon')"]
    C --> E[createLocalDatabase\npg Pool + drizzle node-postgres]
    D --> F[createNeonDatabase\nneon + drizzle neon-http]
    E --> G[export const db: AppDatabase]
    F --> G
Loading

Fix All in Cursor Fix All in Codex

Reviews (2): Last reviewed commit: "Load Neon and pg database drivers throug..." | Re-trigger Greptile

Comment thread src/lib/server/db/index.ts
Copy link
Copy Markdown
Owner Author

x0ba commented May 28, 2026

Merge activity

  • May 28, 4:49 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 28, 4:55 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 28, 4:56 PM UTC: @x0ba merged this pull request with Graphite.

@x0ba x0ba changed the base branch from cold-start/lazy-agent-runner to graphite-base/44 May 28, 2026 16:52
@x0ba x0ba changed the base branch from graphite-base/44 to staging May 28, 2026 16:53
Production bundles no longer parse the local pg driver when running against Neon on Vercel.
@x0ba x0ba force-pushed the cold-start/split-db-drivers branch from e3c51ae to 9b340e6 Compare May 28, 2026 16:55
@x0ba x0ba merged commit 74ff114 into staging May 28, 2026
4 of 5 checks passed
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