Per-Tenant Database Configuration

Per-Tenant Database Configuration

Generator supports configuring separate databases for tenant data, enabling data isolation and horizontal scaling. This feature allows you to store tenant data in dedicated databases, separate from the default database used by the application. You can configure any number of tenants to use any number of databases, providing flexibility to group tenants by database as needed.

How It Works

When tenants are configured to use a dedicated database, their data is stored in that database rather than the default database. System-level data that exists outside of any specific tenant (such as system-level configuration and API credential information) continues to be stored in the default database. This architecture provides:

  • Data Isolation: Complete separation of tenant data for security and compliance requirements
  • Horizontal Scaling: Distribute database load across multiple database instances
  • Performance Optimization: Isolate high-traffic tenants to dedicated database resources

Configuration Steps

To configure tenants to use a separate database, follow these steps:

  1. Create the Database: Create a new PostgreSQL database following the “Create Database” step in the installation guide. Ensure the database has both the public and content_store schemas with the required extensions (pg_trgm and vector).

  2. Install the Schema: Use Generator’s schema migration tool to install Generator’s schema on the new database. Use the install command with a connection string to the new database. For detailed usage instructions and examples, see the Schema Migrations documentation.

  3. Configure the Tenant(s): Use the PUT /api/v1/config/DB__TENANT_DB_CONNECTION_STRING endpoint to configure each tenant to use the database. Multiple tenants can be configured to use the same database by setting the same connection string for each tenant. The connection string should follow the standard PostgreSQL connection string format (e.g., postgresql+psycopg2://user:password@host:port/database).

Schema Migration Considerations

When upgrading your Generator instance, you’ll need to upgrade both the default database and any configured per-tenant databases to ensure they’re all running the latest schema version.

  • Upgrading Tenant Databases: Use the upgrade command with the --tenant flag to upgrade a specific tenant’s database. For example: ./upgrade_schema.sh upgrade --tenant "tenant-id"

  • Checking Migration Status: Use the audit command to check the migration status across all configured tenant databases. This helps identify which databases need schema updates.

For complete documentation on the migration tool commands, usage examples, and upgrade procedures, see the Schema Migrations documentation.