Initialization and customization
The diagram below describes what happens when a tenant is created:
sequenceDiagram
autonumber
participant T as TenantManagement
participant B as Business Cluster
T->>T: Log as full-admin
T->>T: tenant creation (UI)
T->>T: tenant admin user creation
T->>T: Assign admin to tenant
T->>B: DAPR Pub/sub: CreateTenant
activate B
B->>B: MigrationDB :creation Tenant (separated DB)
B->>T: DAPR Pub/sub : base created (success or error)
Note over B: OnTenantDatabaseMigratedAsync on the tenant
B->>T: DAPR Pub/sub : Tenant created (success or error)
deactivate B
- Step 5, the tenant management send message to the business cluster to create the new tenant. In fact, only the business cluster knows the format of its database and all its entities.
- Step 6, the database is migrated (or created if new).
- Step 7, the migration process runs the
ITenantDatabaseMigrationInterceptor.OnTenantDatabaseMigratedAsync
interceptors. To configure it, see Registering a tenant database migration interceptor
How to execute SQL operations during database migration?
Database migrations can be customized using classes implementing the IMigrationInterceptor interface.
This allows you to add commands that initialize required columns with default values during the migration.
For more informations, check this article.