From 0772989b108e883a27936d40284861cd46292b7e Mon Sep 17 00:00:00 2001 From: Lasse Rune Hansen Date: Sun, 31 May 2026 19:40:34 +0200 Subject: [PATCH] feat(backend/infra): configure PostgreSQL database for EF Core - Replace SQLite with Npgsql provider - Update Program.cs to use UseNpgsql - Add connection strings to appsettings files - Create appsettings.Staging.json and appsettings.Production.json Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe --- GermanApp/GermanApp.csproj | 2 +- GermanApp/Program.cs | 8 ++++---- GermanApp/appsettings.Development.json | 7 +++++-- GermanApp/appsettings.Production.json | 11 +++++++++++ GermanApp/appsettings.Staging.json | 11 +++++++++++ GermanApp/appsettings.json | 5 ++++- 6 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 GermanApp/appsettings.Production.json create mode 100644 GermanApp/appsettings.Staging.json diff --git a/GermanApp/GermanApp.csproj b/GermanApp/GermanApp.csproj index 824b0c5..da9d6b3 100644 --- a/GermanApp/GermanApp.csproj +++ b/GermanApp/GermanApp.csproj @@ -10,7 +10,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/GermanApp/Program.cs b/GermanApp/Program.cs index 0133d3f..a7c0db3 100644 --- a/GermanApp/Program.cs +++ b/GermanApp/Program.cs @@ -16,12 +16,12 @@ builder.Services.AddOpenApi(); // INFRASTRUCTURE LAYER - Database & External Services // ============================================ -// Add DbContext with SQLite (can be changed to SQL Server, PostgreSQL, etc.) +// Add DbContext with PostgreSQL builder.Services.AddDbContext(options => { - // Using SQLite for development - configure in appsettings.json for production - options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection") - ?? "Data Source=germanapp.db"); + // Using PostgreSQL for production and development + options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection") + ?? "Host=localhost;Port=5432;Database=DeutschLernen;Username=postgres;Password=postgres"); // Enable sensitive data logging in development if (builder.Environment.IsDevelopment()) diff --git a/GermanApp/appsettings.Development.json b/GermanApp/appsettings.Development.json index ff66ba6..045b0f3 100644 --- a/GermanApp/appsettings.Development.json +++ b/GermanApp/appsettings.Development.json @@ -1,8 +1,11 @@ { "Logging": { "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" + "Default": "Debug", + "Microsoft.AspNetCore": "Information" } + }, + "ConnectionStrings": { + "DefaultConnection": "Host=localhost;Port=5432;Database=DeutschLernen;Username=postgres;Password=postgres" } } diff --git a/GermanApp/appsettings.Production.json b/GermanApp/appsettings.Production.json new file mode 100644 index 0000000..4dd231b --- /dev/null +++ b/GermanApp/appsettings.Production.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning", + "Microsoft.AspNetCore": "Error" + } + }, + "ConnectionStrings": { + "DefaultConnection": "Host=prod-db;Port=5432;Database=DeutschLernen;Username=postgres;Password=${DB_PASSWORD}" + } +} diff --git a/GermanApp/appsettings.Staging.json b/GermanApp/appsettings.Staging.json new file mode 100644 index 0000000..4635bcd --- /dev/null +++ b/GermanApp/appsettings.Staging.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings": { + "DefaultConnection": "Host=staging-db;Port=5432;Database=DeutschLernen;Username=postgres;Password=${DB_PASSWORD}" + } +} diff --git a/GermanApp/appsettings.json b/GermanApp/appsettings.json index 4d56694..7b19f94 100644 --- a/GermanApp/appsettings.json +++ b/GermanApp/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "DefaultConnection": "Host=localhost;Port=5432;Database=DeutschLernen;Username=postgres;Password=postgres" + } }