Nile provides built-in multi-tenancy support. This guide covers all tenant management commands and their usage.

nile tenants [command] [options]

Available commands:

  • list - View all tenants
  • create - Create a new tenant
  • delete - Remove a tenant
  • update - Modify tenant details

Prerequisites

Before managing tenants, ensure you have:

  1. Selected a workspace
  2. Selected a database
  3. Authenticated with Nile
Prerequisites
# Set workspace and database
nile config --workspace my-workspace --db my-database

# Verify configuration
nile config

Listing Tenants

The list command shows all tenants in your database.

nile tenants list [options]

Options

FlagDescriptionDefault
--formatOutput format (human, json, csv)human
--workspaceWorkspace containing the databaseCurrent workspace
--dbDatabase to list tenants fromCurrent database

Examples

List Examples
# Basic list
nile tenants list

# JSON format
nile tenants list --format json

# List from specific database
nile tenants list --db customer-db

Creating Tenants

The create command adds a new tenant to your database.

nile tenants create [options]

Required Options

FlagDescription
--nameName of the tenant

Additional Options

FlagDescriptionDefault
--idCustom ID for the tenantAuto-generated
--formatOutput format (human, json, csv)human
--workspaceWorkspace containing the databaseCurrent workspace
--dbDatabase to create tenant inCurrent database

Examples

Create Examples
# Create with auto-generated ID
nile tenants create --name "Acme Corp"

# Create with custom ID
nile tenants create --name "Globex Inc" --id globex-2024

# Create with JSON output
nile tenants create --name "Initech" --format json

Updating Tenants

The update command modifies existing tenant details.

nile tenants update [options]

Required Options

FlagDescription
--idID of the tenant to update
--new_nameNew name for the tenant

Additional Options

FlagDescriptionDefault
--formatOutput format (human, json, csv)human
--workspaceWorkspace containing the databaseCurrent workspace
--dbDatabase containing the tenantCurrent database

Examples

Update Examples
# Update tenant name
nile tenants update --id tenant_123 --new_name "Acme Corporation"

# Update with JSON output
nile tenants update --id tenant_123 --new_name "Acme Corp Ltd" --format json

# Update in specific database
nile tenants update --id tenant_123 --new_name "New Name" --db customer-db

Deleting Tenants

The delete command removes a tenant from your database.

nile tenants delete [options]

Required Options

FlagDescription
--idID of the tenant to delete

Additional Options

FlagDescriptionDefault
--forceSkip confirmation promptfalse
--workspaceWorkspace containing the databaseCurrent workspace
--dbDatabase containing the tenantCurrent database

Examples

Delete Examples
# Delete with confirmation
nile tenants delete --id tenant_123

# Force delete without confirmation
nile tenants delete --id tenant_123 --force

# Delete from specific database
nile tenants delete --id tenant_123 --db customer-db

Common Workflows

Setting Up Initial Tenants

Initial Setup
# 1. Create main tenant
nile tenants create --name "Main Customer"

# 2. Create additional tenants
nile tenants create --name "Customer A"
nile tenants create --name "Customer B"

# 3. Verify creation
nile tenants list

Tenant Maintenance

Maintenance
# 1. List all tenants
nile tenants list

# 2. Update names if needed
nile tenants update --id tenant_123 --new_name "Updated Name"

# 3. Remove unused tenants
nile tenants delete --id tenant_456 --force

Bulk Operations

Bulk Operations
# List all tenants in JSON format
nile tenants list --format json > tenants.json

# Create multiple tenants
cat tenants.txt | while read name; do
  nile tenants create --name "$name"
done

# Update multiple tenants
cat updates.txt | while read id name; do
  nile tenants update --id "$id" --new_name "$name"
done

Common Issues

Tenant Not Found

When tenant doesn’t exist:

Not Found
# Try to update non-existent tenant
nile tenants update --id invalid_id --new_name "New Name"
Error: Tenant 'invalid_id' not found

# List available tenants
nile tenants list

Database Not Selected

When database isn’t specified:

No Database
# Try without database selected
nile tenants list
Error: No database specified

# Solution: Set database
nile config --db my-database

Duplicate Tenant ID

When creating tenant with existing ID:

Duplicate ID
# Try to create with existing ID
nile tenants create --name "New Tenant" --id existing_id
Error: Tenant ID 'existing_id' already exists

# Use auto-generated ID instead
nile tenants create --name "New Tenant"

Best Practices

  1. Naming Conventions: Use clear, consistent tenant names:

    nile tenants create --name "Company Name - Environment"
    
  2. Regular Verification: Periodically verify tenant list:

    nile tenants list --format json > tenant_audit.json
    
  3. Backup Before Delete: List tenant details before deletion:

    nile tenants list > tenants_backup.txt
    
  • nile db psql - Connect to tenant’s database
  • nile db connectionstring - Get tenant-specific connection
  • nile config - Configure CLI settings
  • nile workspace - Manage workspaces

Was this page helpful?