Skip to content

Conversation

@gcarvelli
Copy link

Summary

Replace better-sqlite3 and filesystem imports in src/lib/db/index.ts with Cloudflare D1 API. All database functions are now async and use D1 bindings from process.env, resolving the "Operation not permitted" error in Cloudflare Workers.

Changes

  • Rewrote src/lib/db/index.ts to use D1 async API instead of better-sqlite3
  • Removed all fs/path imports and filesystem access (schema loading, WAL pragmas, migrations)
  • Deleted redundant src/lib/db/d1.ts adapter
  • Updated 11 consumers (3 server components, 8 API routes) to use await for all DB calls
  • Build succeeds with no errors; app bundle contains zero better-sqlite3 or fs imports

Test Plan

  • npm run build — Production build succeeds
  • Run npx wrangler dev to test with local D1 simulator
  • Deploy to Cloudflare Workers to verify "Operation not permitted" is resolved

gcarvelli and others added 2 commits February 6, 2026 15:02
Replace all filesystem and better-sqlite3 imports in src/lib/db/index.ts with D1 API. All database functions are now async. Removed better-sqlite3-specific setup (fs reads, schema loading, WAL pragmas) and all sync-only functions used only by scripts. Updated all 11 consumers (3 server components, 8 API routes) to use await for DB calls.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant