Skip to content

D1 multi tenant improvements and test coverage#50

Open
ataylorme wants to merge 29 commits intozpg6:feat/d1-multi-tenancyfrom
ataylorme:feat/d1-multi-tenancy
Open

D1 multi tenant improvements and test coverage#50
ataylorme wants to merge 29 commits intozpg6:feat/d1-multi-tenancyfrom
ataylorme:feat/d1-multi-tenancy

Conversation

@ataylorme
Copy link

@ataylorme ataylorme commented Mar 16, 2026

Continuing work on #17

Copilot AI and others added 29 commits January 2, 2026 00:14
Co-authored-by: ataylorme <2133004+ataylorme@users.noreply.github.com>
Co-authored-by: ataylorme <2133004+ataylorme@users.noreply.github.com>
Co-authored-by: ataylorme <2133004+ataylorme@users.noreply.github.com>
Co-authored-by: ataylorme <2133004+ataylorme@users.noreply.github.com>
Co-authored-by: ataylorme <2133004+ataylorme@users.noreply.github.com>
- Add comprehensive schema detection and validation utilities
- Add tests for plugin table placement and relationships
- Document how to handle Better Auth plugins with multi-tenancy
- Add 24 new tests for schema management (all passing)
- Provide utilities to detect cross-database references
- Document migration strategies for plugin-added tables

Co-authored-by: ataylorme <2133004+ataylorme@users.noreply.github.com>
Implement Universal ID-based sharding for D1 multi-tenancy with plugin support
…nges

Co-authored-by: ataylorme <2133004+ataylorme@users.noreply.github.com>
…mentation

Update examples and documentation for PR #1 Universal ID sharding
Co-authored-by: ataylorme <2133004+ataylorme@users.noreply.github.com>
Add full test coverage for D1 multi-tenancy features with Drizzle mocking
…store

Co-authored-by: ataylorme <2133004+ataylorme@users.noreply.github.com>
Co-authored-by: ataylorme <2133004+ataylorme@users.noreply.github.com>
Add Cloudflare KV as persistent L2 backing store for the shard cache
- Migrate from Jest to Vitest with ESM support and vi.hoisted() for mock hoisting
- Add @faker-js/faker for realistic test data generation
- Add nock for HTTP-level Cloudflare D1 API mocking in integration tests
- Add drizzle-kit and wrangler as dev dependencies
- Add new sharding-multi-db test suite covering:
  - Multi-DB routing via Universal IDs
  - Batch tenant creation with unique UUIDs
  - Shard cache population and FIFO eviction under load
  - Database full/limit exceeded error handling
  - Migration failure during DB initialization
  - Data validation across shards (deterministic hashes, status transitions)
- Add integration-sharding test suite covering:
  - Full tenant lifecycle (create + delete) for user and org modes
  - Batch creation of 10 tenants with nock interceptors
  - Error recovery: API limits, HTTP 500, 403, network timeouts
  - Shard cache hydration from adapter with 25 tenants
  - Universal ID routing across 5 shard databases
  - KV write-through during tenant creation
  - Concurrent tenant creation
  - Schema SQL execution with statement breakpoints
- Create GitHub Actions test.yml workflow with:
  - Unit/integration tests on Node 20, 22, 24
  - Typecheck job
  - Matrix-based sharding scenario jobs running each test file independently

Total: 181 tests across 9 test files, all passing.

https://claude.ai/code/session_013ggvpkaVD7QivK8XaS4YMB
- Use getPlatformProxy() with wrangler.test.toml to provide 10 real
  SQLite-backed D1 database bindings for testing
- Replace all vi.mock("@zpg6-test-pkgs/drizzle-orm/d1-http") stubs with
  a redirector that routes drizzle calls to real D1 bindings via the d1
  binding driver
- Remove all nock HTTP mocking from integration tests
- Replace fetch mocks for Cloudflare REST API (create/delete database)
  with createLocalD1Fetch interceptor that performs real local D1 ops
- Add node:fs verification helpers (assertD1FilesExist, listD1SqliteFiles)
  to verify SQLite files on disk
- Create shared vitest setup file (setup.ts) with vi.stubEnv, D1 pool
  init, and common beforeEach/afterEach hooks
- Add helpers.ts with D1Pool management, adapter factories, and query
  verification utilities
- Update GitHub Actions to pass RUNNER_TEMP for wrangler persistence path
- All 184 tests pass against real SQLite-backed D1 instances

https://claude.ai/code/session_013ggvpkaVD7QivK8XaS4YMB
Add support for 'feat/d1-multi-tenancy' branch in test workflow
Removed environment variable RUNNER_TEMP from sharding scenarios.
- Add per-scenario test scripts (test:sharding, test:integration, etc.) to package.json
- Add concurrency group with cancel-in-progress to all 8 workflow files

https://claude.ai/code/session_013ggvpkaVD7QivK8XaS4YMB
@ataylorme ataylorme mentioned this pull request Mar 16, 2026
15 tasks
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.

3 participants