Xabaril / AspNetCore.Diagnostics.HealthChecks

Enterprise HealthChecks for ASP.NET Core Diagnostics Package
Apache License 2.0
4.05k stars 793 forks source link

UI Storage providers - Tables custom prefix #481

Open CarlosLanderas opened 4 years ago

CarlosLanderas commented 4 years ago

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!

OskarKlintrot commented 4 years ago

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

IeuanWalker commented 4 years ago

@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

rj-digimuth commented 3 years ago

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.

CarlosLanderas commented 3 years ago

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);
                });
camiteca commented 3 years ago

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

erikrenaud commented 3 years ago

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 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.

unchase commented 3 years ago

Hi, @CarlosLanderas

Are you planning to add this feature soon?

camedool commented 2 years ago

Hi @CarlosLanderas ,

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

HeardsTheWord commented 1 year ago

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?

NinjaCross commented 1 year ago

Hi @CarlosLanderas ! Any news about this ?

sungam3r commented 1 year ago

fixed in #1858

MelGrubb commented 1 year ago

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.

DexMRS commented 7 months ago

Any updates?

sungam3r commented 7 months ago

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.