Base solution for your next web application

Activities of "swx"

Hi AspNetZero and fellow coders (AIs included),

Are there any instructions/documentation on how to support two different databases in parallel?

Some background:

  • Our application is based on ASP.NET CORE & Angular, version 12.1.0. and is using Hangfire.
  • The database is MSSQL 2019 and it includes views, functions and stored procedures, integrted in the migration as external scripts/seeds.
  • The entities are defined in dedicated configurations (IEntityTypeConfiguration) and integrated in AppDbContext (i.e. modelBuilder.ApplyConfiguration(new UserInvitationConfiguration());)

The requirement is to support PostgreSQL 15 in parallel, using as much as possible the same base code. That doesn't mean to connect to two databases at the same time, but to be able to deploy the application using either MSSQL or PostgreSQL.

Following the tutorial, I managed to completely re-create the application and use Postgres, by removing the existing migrations and rewriting the views, functions and stored procedures

What I couldn't figure out is: how to structure the code in a way that we maintain compatibility with the two databases in the same base code. This would be the expected scenario:

  1. Maintain two migration sets, one for each database
  2. Update/Create a database, targeting one of the migration sets and relative seed scripts
  3. Start the application dynamically, considering:
    1. Database type in AppDbContextConfigurer (builder.UseSqlServer(connectionString) vs builder.UseNpgsql(connectionString);)
    2. Hangfire start in Program.cs ( config.UseSqlServerStorage(_appConfiguration.GetConnectionString("Default")); vs config.UsePostgreSqlStorage(_appConfiguration.GetConnectionString("Default"));)

Any suggestions are greatly appreciated.

Best regards

Showing 1 to 1 of 1 entries