-
Notifications
You must be signed in to change notification settings - Fork 164
Managing sharding databases
The AuthP library has a AuthPermissions.SupportCode project which contains a service called AccessDatabaseInformation. This can be used to alter the list of database information in the shardingsettings.json file in development and production.
This service provides the following methods:
-
ReadShardingSettingsFile- read theshardingsettings.jsonfile - useful for showing all the content of the file. -
GetDatabaseInformationByName(name)- read a specific database information. Used when editing / deleting an entry. -
AddDatabaseInfoToJsonFile(info)- Adds a new database information to theshardingsettings.jsonfile. -
UpdateDatabaseInfoToJsonFile(info)- Updates the database information with the givenName. -
RemoveDatabaseInfoToJsonFileAsync(name)- Removes the database information with the givenName.
NOTE: You need to manually register this service as its not part of the AuthP setup. See this code from the application's Program class.
//manually add services from the AuthPermissions.SupportCode project
builder.Services.AddTransient<IAccessDatabaseInformation, AccessDatabaseInformation>();You can see the AccessDatabaseInformation method running in the Example6.MvcWebApp.Sharding web application. Log in as an application admin user and click the Auth Admin -> List database info. The code for these can be found in the ShardingController class of Example 6. See the screenshot below:

Another useful display is a list of databases showing what tenants are in each database and whether the tenant is using Sharding, i.e. they have their own database. This uses the GetDatabaseInfoNamesWithTenantNamesAsync method and the code is found in the TenantController class of Example 6. See the screenshot below:

This is useful as the "Sharding?" column tells you the sharding setting for each database:
- False: The database is holding tenant(s) that aren't using sharding, i.e.
HasOwnDbisfalse - True: The database is holding one tenant that is using sharding, i.e.
HasOwnDbistrue - Empty: The database hasn't got any tenants in it, i.e.
HasOwnDbisnull
NOTE: This method will always False for the the database with default connection string as that database contains AuthP's data.
- Intro to multi-tenants (ASP.NET video)
- Articles in date order:
- 0. Improved Roles/Permissions
- 1. Setting up the database
- 2. Admin: adding users and tenants
- 3. Versioning your app
- 4. Hierarchical multi-tenant
- 5. Advanced technique with claims
- 6. Sharding multi-tenant setup
- 7. Three ways to add new users
- 8. The design of the sharding data
- 9. Down for maintenance article
- 10: Three ways to refresh claims
- 11. Features of Multilingual service
- 12. Custom databases - Part1
- Videos (old)
- Authentication explained
- Permissions explained
- Roles explained
- AuthUser explained
- Multi tenant explained
- Sharding explained
- How AuthP handles sharding
- How AuthP handles errors
- Languages & cultures explained
- JWT Token refresh explained
- Setup Permissions
- Setup Authentication
- Startup code
- Setup the custom database feature
- JWT Token configuration
- Multi tenant configuration
- Using Permissions
- Using JWT Tokens
- Creating a multi-tenant app
- Supporting multiple languages
- Unit Test your AuthP app