Tenant Commands¶
Manage multi-tenant data isolation.
Overview¶
Tenants provide complete data isolation while sharing the same schema. Each tenant has separate SQLite database files.
list¶
List all tenants in the current branch.
Example Output¶
create¶
Create a new tenant.
Arguments¶
TENANT_NAME
- Name for the new tenant
Examples¶
# Create single tenant
cinch tenant create customer_a
# Create multiple tenants
cinch tenant create acme_corp
cinch tenant create wayne_enterprises
Notes¶
- Tenant names must be unique within a branch
- Creates new SQLite database file for the tenant
- Inherits current branch schema automatically
delete¶
Delete a tenant and all its data.
Arguments¶
TENANT_NAME
- Tenant to delete
Options¶
--force
- Skip confirmation
Example¶
# With confirmation
cinch tenant delete old_customer
# Without confirmation
cinch tenant delete old_customer --force
Warning¶
- Permanently deletes all tenant data
- Cannot delete the
main
tenant - Cannot be undone
rename¶
Rename a tenant.
Arguments¶
OLD_NAME
- Current tenant nameNEW_NAME
- New tenant name
Example¶
copy¶
Create a new tenant by copying an existing one.
Arguments¶
SOURCE_TENANT
- Tenant to copy fromNEW_TENANT
- Name for the new tenant
Options¶
--no-data
- Copy schema only (default: copies data too)
Examples¶
# Copy with data
cinch tenant copy template_tenant customer_b
# Copy schema only
cinch tenant copy main new_customer --no-data
Working with Tenants¶
Query Specific Tenant¶
# Query tenant data
cinch query "SELECT * FROM users" --tenant acme_corp
# Insert into tenant
cinch insert users --tenant acme_corp --data '{"name": "Alice", "email": "alice@acme.com"}'
Tenant-Specific Operations¶
All commands support --tenant
flag:
# Table info for tenant
cinch table info users --tenant customer_a
# Create view for tenant
cinch view create active_users "SELECT * FROM users WHERE active = true" --tenant customer_a
Common Use Cases¶
SaaS Applications¶
# Create tenant per customer
cinch tenant create customer_001
cinch tenant create customer_002
# Customer-specific data
cinch insert settings --tenant customer_001 --data '{"key": "theme", "value": "dark"}'
Development/Testing¶
# Create test tenants
cinch tenant create test_env
cinch tenant create staging_env
# Copy production data for testing
cinch tenant copy main test_env
Multi-Region Setup¶
# Regional tenants
cinch tenant create us_east
cinch tenant create us_west
cinch tenant create eu_central
cinch tenant create asia_pacific
Schema Synchronization¶
Schema changes automatically apply to all tenants:
# Add column - affects all tenants
cinch column add users phone:TEXT
# Verify across tenants
cinch table info users --tenant main
cinch table info users --tenant customer_a
Tenant Isolation¶
Each tenant has: - Separate SQLite database file - Complete data isolation - Shared schema definition - Independent query execution
Example file structure:
.cinchdb/databases/main/branches/main/tenants/
├── main.db
├── customer_a.db
├── customer_b.db
└── customer_c.db
Best Practices¶
- Naming Conventions
- Use lowercase with underscores
- Include customer/region identifiers
-
Avoid special characters
-
Template Tenant
- Create a template tenant with default data
-
Copy from template for new customers
-
Regular Cleanup
- Remove inactive tenants
- Archive old tenant data
-
Monitor tenant disk usage
-
Access Control
- Map API keys to specific tenants
- Implement tenant filtering in application
- Log tenant access for auditing
Performance Considerations¶
- Each tenant has separate SQLite file
- No cross-tenant query overhead
- Linear scaling with tenant count
- Consider sharding for many tenants (1000+)
Migration Patterns¶
Onboarding New Customer¶
# Create tenant
cinch tenant create bigcorp
# Import initial data
cinch query "INSERT INTO users SELECT * FROM import_table" --tenant bigcorp
# Verify setup
cinch query "SELECT COUNT(*) FROM users" --tenant bigcorp
Tenant Data Export¶
# Export tenant data
cinch query "SELECT * FROM users" --tenant customer_a --format csv > customer_a_users.csv
Remote Operations¶
Next Steps¶
- Query Command - Query tenant data
- Multi-Tenancy Concepts - Deep dive
- Multi-Tenant Tutorial - Build an app