adding complete db migrations from posgres
This commit is contained in:
@@ -17,9 +17,7 @@ using ERPCore.System.Errors;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.OpenApi;
|
||||
using Npgsql;
|
||||
using Serilog;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
@@ -33,11 +31,17 @@ builder.Host.UseSerilog((ctx, cfg) => cfg
|
||||
builder.Services.AddControllers()
|
||||
.AddJsonOptions(o => o.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
|
||||
|
||||
// EF Core + PostgreSQL
|
||||
// EF Core + MariaDB (Pomelo). The server version is pinned explicitly rather than using
|
||||
// ServerVersion.AutoDetect: AutoDetect opens a connection, which would make design-time
|
||||
// commands (`dotnet ef migrations add`) and startup depend on the database being reachable.
|
||||
// MariaDbServerVersion — not MySqlServerVersion — because the target is MariaDB 10.11, and
|
||||
// Pomelo changes its SQL translation based on which it is given.
|
||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection")
|
||||
?? throw new InvalidOperationException("ConnectionStrings:DefaultConnection is not configured.");
|
||||
|
||||
builder.Services.AddDbContext<ErpDbContext>(o =>
|
||||
{
|
||||
o.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"));
|
||||
o.ConfigureWarnings(w => w.Ignore(RelationalEventId.PendingModelChangesWarning));
|
||||
o.UseMySql(connectionString, new MariaDbServerVersion(new Version(10, 11, 15)));
|
||||
});
|
||||
|
||||
// ProblemDetails (RFC 7807) + domain-exception mapping
|
||||
|
||||
Reference in New Issue
Block a user