From cda19e2b83fa7a2b0eb1233d8caaf9579d4d10a8 Mon Sep 17 00:00:00 2001 From: TekH Date: Mon, 30 Jun 2025 15:29:47 +0200 Subject: [PATCH] Add migration support and update launch settings Introduce `useDbMigration` variable in `Program.cs` to conditionally manage database migrations based on environment settings. Update `launchSettings.json` to include a new `httpsDbMigration` profile for testing with Swagger UI. Modify `appsettings.json` to add `UseDbMigration` setting and replace the "Dev" connection string with "DbMigrationTest" for migration testing. --- EnvelopeGenerator.Web/Program.cs | 1 + .../Properties/launchSettings.json | 13 ++++++++++++- EnvelopeGenerator.Web/appsettings.json | 3 ++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/EnvelopeGenerator.Web/Program.cs b/EnvelopeGenerator.Web/Program.cs index e6df2f8f..8508bfaf 100644 --- a/EnvelopeGenerator.Web/Program.cs +++ b/EnvelopeGenerator.Web/Program.cs @@ -88,6 +88,7 @@ try } //AddEF Core dbcontext + var useDbMigration = Environment.GetEnvironmentVariable("MIGRATION_TEST_MODE") == true.ToString() || config.GetValue("UseDbMigration"); var connStr = config.GetConnectionString(Key.Default) ?? throw new InvalidOperationException("There is no default connection string in appsettings.json."); builder.Services.AddDistributedSqlServerCache(options => diff --git a/EnvelopeGenerator.Web/Properties/launchSettings.json b/EnvelopeGenerator.Web/Properties/launchSettings.json index ecea07e7..ccccee4d 100644 --- a/EnvelopeGenerator.Web/Properties/launchSettings.json +++ b/EnvelopeGenerator.Web/Properties/launchSettings.json @@ -16,7 +16,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" } }, - "swagger": { + "https": { "commandName": "Project", "launchBrowser": true, "launchUrl": "swagger", @@ -25,6 +25,17 @@ }, "dotnetRunMessages": true, "applicationUrl": "https://localhost:7202;http://localhost:5009" + }, + "httpsDbMigration": { + "commandName": "Project", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "MIGRATION_TEST_MODE": "true" + }, + "dotnetRunMessages": true, + "applicationUrl": "https://localhost:7202;http://localhost:5009" } }, "iisSettings": { diff --git a/EnvelopeGenerator.Web/appsettings.json b/EnvelopeGenerator.Web/appsettings.json index ee9811dc..6c26db74 100644 --- a/EnvelopeGenerator.Web/appsettings.json +++ b/EnvelopeGenerator.Web/appsettings.json @@ -1,6 +1,7 @@ { "DiPMode": false, //Please be careful when enabling Development in Production (DiP) mode. It allows Swagger and test controllers to be enabled in a production environment. "EnableSwagger": true, + "UseDbMigration": false, "EnableTestControllers": true, "DetailedErrors": true, "Logging": { @@ -13,7 +14,7 @@ }, "ConnectionStrings": { "Default": "Server=SDD-VMP04-SQL17\\DD_DEVELOP01;Database=DD_ECM;User Id=sa;Password=dd;Encrypt=false;TrustServerCertificate=True;", - "Dev": "Server=SDD-VMP04-SQL17\\DD_DEVELOP01;Database=DD_ECM_DATA_MIGR_TEST;User Id=sa;Password=dd;Encrypt=false;TrustServerCertificate=True;" + "DbMigrationTest": "Server=SDD-VMP04-SQL17\\DD_DEVELOP01;Database=DD_ECM_DATA_MIGR_TEST;User Id=sa;Password=dd;Encrypt=false;TrustServerCertificate=True;" }, "PSPDFKitLicenseKey": "SXCtGGY9XA-31OGUXQK-r7c6AkdLGPm2ljuyDr1qu0kkhLvydg-Do-fxpNUF4Rq3fS_xAnZRNFRHbXpE6sQ2BMcCSVTcXVJO6tPviexjpiT-HnrDEySlUERJnnvh-tmeOWprxS6BySPnSILkmaVQtUfOIUS-cUbvvEYHTvQBKbSF8di4XHQFyfv49ihr51axm3NVV3AXwh2EiKL5C5XdqBZ4sQ4O7vXBjM2zvxdPxlxdcNYmiU83uAzw7B83O_jubPzya4CdUHh_YH7Nlp2gP56MeG1Sw2JhMtfG3Rj14Sg4ctaeL9p6AEWca5dDjJ2li5tFIV2fQSsw6A_cowLu0gtMm5i8IfJXeIcQbMC2-0wGv1oe9hZYJvFMdzhTM_FiejM0agemxt3lJyzuyP8zbBSOgp7Si6A85krLWPZptyZBTG7pp7IHboUHfPMxCXqi-zMsqewOJtQBE2mjntU-lPryKnssOpMPfswwQX7QSkJYV5EMqNmEhQX6mEkp2wcqFzMC7bJQew1aO4pOpvChUaMvb1vgRek0HxLag0nwQYX2YrYGh7F_xXJs-8HNwJe8H0-eW4x4faayCgM5rB5772CCCsD9ThZcvXFrjNHHLGJ8WuBUFm6LArvSfFQdii_7j-_sqHMpeKZt26NFgivj1A==", "Content-Security-Policy": [ // The first format parameter {0} will be replaced by the nonce value.