Skip to content

Add flexible driver configuration for organization databases#1176

Closed
Claude wants to merge 2 commits intomainfrom
claude/check-tenant-service-code
Closed

Add flexible driver configuration for organization databases#1176
Claude wants to merge 2 commits intomainfrom
claude/check-tenant-service-code

Conversation

@Claude
Copy link
Copy Markdown
Contributor

@Claude Claude AI commented Apr 17, 2026

Organizations can now specify their database driver type (Turso, Memory, SQL, SQLite, Custom) instead of being limited to hardcoded Turso configuration. This enables flexible deployment scenarios: memory drivers for development/testing, Turso for production cloud, PostgreSQL/MySQL for enterprise on-premise, and custom drivers for proprietary implementations.

Changes

Schema Updates (packages/spec/src/cloud/tenant.zod.ts)

  • Added DriverConfigSchema discriminated union supporting 5 driver types
  • Added type-specific config schemas: TursoDriverConfigSchema, MemoryDriverConfigSchema, SQLDriverConfigSchema, SQLiteDriverConfigSchema, CustomDriverConfigSchema
  • Updated TenantDatabaseSchema to use driverConfig field instead of separate databaseName, databaseUrl, authToken, region fields
  • Updated ProvisionTenantRequestSchema to accept driverConfig parameter

Provisioning Service (packages/services/service-tenant/src/tenant-provisioning.ts)

  • Refactored provisionTenant() to dispatch based on driver type
  • Added driver-specific provisioning methods: provisionTursoDatabase(), provisionMemoryDriver(), provisionSQLDatabase(), provisionSQLiteDatabase(), provisionCustomDriver()
  • Updated storeTenantRecord() to serialize driverConfig as JSON

Driver Factory (packages/services/service-tenant/src/driver-factory.ts)

  • New DriverFactory class for managing driver instances with caching
  • Type-safe driver instantiation based on configuration
  • Cache key generation for connection pooling

Runtime Resolution (packages/services/service-tenant/src/tenant-context.ts)

  • Added getDriverForOrganization() method to retrieve driver instance for an organization
  • Added getTenantDatabase() to query control plane for driver configuration
  • Integrated DriverFactory for runtime driver creation

Database Schema (packages/services/service-tenant/src/objects/sys-tenant-database.object.ts)

  • Replaced individual fields with driver_config textarea field storing JSON-serialized configuration
  • Removed hardcoded Turso-specific fields

Usage Example

// Production: Turso cloud database
await provisioningService.provisionTenant({
  organizationId: 'org-prod-001',
  driverConfig: {
    driver: 'turso',
    databaseUrl: 'libsql://uuid.turso.io',
    authToken: process.env.TURSO_TOKEN!,
  },
  plan: 'pro',
});

// Development: In-memory database
await provisioningService.provisionTenant({
  organizationId: 'org-dev-001',
  driverConfig: {
    driver: 'memory',
    persistent: false,
  },
  plan: 'free',
});

// Enterprise: PostgreSQL
await provisioningService.provisionTenant({
  organizationId: 'org-enterprise-001',
  driverConfig: {
    driver: 'sql',
    dialect: 'postgresql',
    host: 'localhost',
    port: 5432,
    database: 'org_data',
    username: 'postgres',
    password: process.env.DB_PASSWORD!,
  },
  plan: 'enterprise',
});

Testing

Added comprehensive test coverage:

  • multi-driver.test.ts: Integration tests for all 5 driver types
  • driver-factory.test.ts: Cache key generation and management tests

Documentation

  • DRIVER_CONFIG.md: Complete usage guide with migration path, best practices, and troubleshooting

Claude AI and others added 2 commits April 17, 2026 09:03
- Add DriverConfig discriminated union supporting 5 driver types
- Support Turso, Memory, SQL, SQLite, and Custom drivers
- Update TenantDatabase schema to use driverConfig instead of hardcoded Turso fields
- Update TenantProvisioningService with driver-specific provisioning methods
- Add DriverFactory for runtime driver instance management
- Update TenantContextService with getDriverForOrganization() method
- Update sys_tenant_database object schema to store driver_config
- Enable flexible deployment scenarios (dev/test/prod/enterprise)

Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/ad2ea41d-bf29-42ea-af00-fcc7d6deea5f

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
- Add multi-driver.test.ts with tests for all 5 driver types
- Add driver-factory.test.ts with cache key tests
- Add DRIVER_CONFIG.md with complete usage guide
- Document migration path from hardcoded Turso
- Include examples for dev/staging/prod scenarios
- Add type safety and troubleshooting sections

Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/ad2ea41d-bf29-42ea-af00-fcc7d6deea5f

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 17, 2026

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

Project Deployment Actions Updated (UTC)
objectstack-demo Ready Ready Preview, Comment Apr 17, 2026 9:16am
spec Ready Ready Preview, Comment Apr 17, 2026 9:16am

Request Review

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

Labels

documentation Improvements or additions to documentation size/xl tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants