Skip to content

Managing sharding databases

Jon P Smith edited this page Jun 14, 2022 · 15 revisions

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 the shardingsettings.json file - 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 the shardingsettings.json file.
  • UpdateDatabaseInfoToJsonFile(info) - Updates the database information with the given Name.
  • RemoveDatabaseInfoToJsonFileAsync(name) - Removes the database information with the given Name.

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>();

Example of using this service

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:

List database information

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:

List databases with tenants

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. HasOwnDb is false
  • True: The database is holding one tenant that is using sharding, i.e. HasOwnDb is true
  • Empty: The database hasn't got any tenants in it, i.e. HasOwnDb is null

NOTE: This method will always False for the the database with default connection string as that database contains AuthP's data.

Articles / Videos

Concepts

Setup

Usage

Admin

SupportCode

Clone this wiki locally