Home:ALL Converter>FluentMigrator: How to set default schema for MigrationRunner

FluentMigrator: How to set default schema for MigrationRunner

Ask Time:2020-06-27T20:08:28         Author:Andy N

Json Formatter

I have a multi-tenanted database. The tenant-specific data is stored inside it's own (PostgreSQL) schema.

I'd like to be able to use FluentMigrator to deploy new tenants as required. I've set up an example on GitHub where a HTTP post to an endpoint will deploy a schema. However deploys it to the public schema by default. I'd like to be able to specify the schema to deploy to.

I.e.

public class TenantService: ITenantService {
  private readonly IServiceProvider _provider;

  public TenantService(IServiceProvider provider) {
    _provider = provider;
  }

  public void Create(string tenantName) {
    using(var scope = _provider.CreateScope()) {
      var migrationRunner = scope.ServiceProvider.GetService<IMigrationRunner>();
      // TODO:  Set the default schema = tenantName
      migrationRunner.MigrateUp();
    }
  }
}

How do I set the default schema for the MigrationRunner?

Edit: I've updated the GitHub repo to reflect the accepted answer.

Author:Andy N,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/62609823/fluentmigrator-how-to-set-default-schema-for-migrationrunner
yy