AspNetCore.Diagnostics.HealthChecks icon indicating copy to clipboard operation
AspNetCore.Diagnostics.HealthChecks copied to clipboard

UI Storage providers - Tables custom prefix

Open CarlosLanderas opened this issue 5 years ago • 14 comments

I would like to throw a question for those users that are planning to use the new storage providers.

All storage packages run migrations by default against the database configured in the connection string and like tables before where created internally in sqlite it wasn't necessary to use table prefixes.

If someone wants to run migrations in a database that already has tables, it could be interesting being able to configure a prefix so instead of having a table called Configurations you could prefix it like Healthchecks_Configurations or UI_Configurations (whatever)

What do you think about this idea? Is something you might want/need to have in the public API surface?

Thanks!

CarlosLanderas avatar Apr 15 '20 21:04 CarlosLanderas

If I remember correct, Hangfire uses it's own schema. Would that work here as well?

OskarKlintrot avatar May 20 '20 09:05 OskarKlintrot

@CarlosLanderas I like this idea would also be good to set the table schema, like @OskarKlintrot mentioned, hangfire does this - image

Could probably see how it's done in there repo - https://github.com/HangfireIO/Hangfire/search?q=DefaultSchema&unscoped_q=DefaultSchema

IeuanWalker avatar Jul 24 '20 17:07 IeuanWalker

Yes please. I was very confused when it created seemingly random tables, only two of which are prefixed with HealthCheck (which adds even more chaos). I had to find migration file in this repo to find out which tables to check/clear.

Simple prefix would be enough for me, e.g. HealthCheck_Failures, but custom schema (like HangFire presented in the comment above) would be the best.

Ultimate solution is to move table names and schema to configuration, but that's not so important.

rj-digimuth avatar Dec 05 '20 14:12 rj-digimuth

Hello!. I think this is a important feature too, that's why I opened this thread. I'm currently implementing the ability to configure a custom schema.

This will be included in 5.0.0 (not preview)

cc @unaizorrilla

Sample usage:

.AddSqlServerStorage(cnnString, hcContextOptions => {
                    hcContextOptions.UseSchema("health");
                    //Migrations options removed from UI options and added in provider options
                    //hcContextOptions .DisableMigrations(true);
                });

CarlosLanderas avatar Dec 06 '20 10:12 CarlosLanderas

I've updated to 5.0.1 and the method isn't there. This is related to #647.

camiteca avatar Jan 27 '21 12:01 camiteca

Yes, the ability to set the schema would be great, as well as being able to set the migrations history table name and schema.

Ideally, the ability to work work with an outside DBContext.

I really like the way OpenIDDict does it by just having a .AddOpenIdDictEntities(). my code looks like this :


  public class OIDCContext : DbContext
  {
    public OIDCContext(DbContextOptions<OIDCContext> options, IConfiguration configuration) : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
      base.OnModelCreating(builder);
      builder.HasDefaultSchema("OIDC");
    }
  }

      services.AddDbContext<OIDCContext>(options =>
        {
          var connectionString = configuration.GetConnectionString("SQL");
          options.UseSqlServer(connectionString, o =>
                  {
                    o.EnableRetryOnFailure();
                    o.MigrationsHistoryTable("__Migrations", "OIDC");
                  });
          options.UseOpenIddict();
        });

The way AspNetCore does it is also interesting by having an interface with DbSet<XXX> to be added to any DbContext.

My apps always have multiple dbcontexts for different domains and i have a bit of code that allows you to run the migrations for all of them, or run in a drop-create mode where i run the the generatedSQL for each context on an empty database.

erikrenaud avatar Aug 13 '21 12:08 erikrenaud

Hi, @CarlosLanderas

Are you planning to add this feature soon?

unchase avatar Aug 20 '21 11:08 unchase

Hi @CarlosLanderas ,

Is it still planned to add extension for custom schema setup? Thanks!

camedool avatar Dec 09 '21 13:12 camedool

I am on 6.0.5, and I do not see the ability to update the schema for all SqlServer.Storage tables. I can change the MigrationsHistory table, but that appears to be the only table that can be updated.

.AddSqlServerStorage(connectionString, configureOptions =>
            {
                configureOptions.UseSqlServer(serverOptions =>
                {
                    serverOptions.MigrationsHistoryTable("HealthChecksMigrationHistory", schema: "HealthChecks");
                });
            });

@CarlosLanderas Is still still a planned feature for all of the tables?

HeardsTheWord avatar Feb 02 '23 14:02 HeardsTheWord

Hi @CarlosLanderas ! Any news about this ?

NinjaCross avatar May 02 '23 15:05 NinjaCross

fixed in #1858

sungam3r avatar Jul 05 '23 11:07 sungam3r

I could be missing something here, but I don't see how #1858 addresses the original issue. I still don't see how we can change the table prefix or set a custom schema. So far, I only see an option to change the history table name/schema, but none of the others. Is there documentation somewhere for the new functionality? I'm not finding it by poking around with Intellisense, that's for sure.

MelGrubb avatar Aug 14 '23 16:08 MelGrubb

Any updates?

DexMRS avatar Feb 17 '24 08:02 DexMRS

Unfortunately no. I remember about that issue and track all activity in repo but I'm very limited in time to support project. I hope to return here some time later.

sungam3r avatar Feb 20 '24 05:02 sungam3r