From dbf9e841f86a9fe3f65a7a7dc242f6400f279469 Mon Sep 17 00:00:00 2001 From: ImanThiyanga Date: Mon, 5 Oct 2026 17:40:04 +0530 Subject: [PATCH] update on production db --- .gitea/workflows/ci-cd.yml | 16 +++++++++++++++- Backend/ERPCore/Program.cs | 10 ++++++++-- Backend/ERPCore/appsettings.json | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml index 93b3b5a..d2ab242 100644 --- a/.gitea/workflows/ci-cd.yml +++ b/.gitea/workflows/ci-cd.yml @@ -45,10 +45,24 @@ jobs: find /home/erp/core/publish -type f -exec chmod 644 {} + chmod +x /home/erp/core/publish/ERPCore - name: Restart service + # ConnectionStrings__DefaultConnection is supplied by the systemd unit on the host + # (Environment= or EnvironmentFile=), deliberately not committed: appsettings.json ships + # the key empty and appsettings.Production.json carries no ConnectionStrings section at + # all. If the unit does not set it, startup throws before serving and the Verify step + # below fails the job. run: systemctl restart erpcore.service - name: Verify run: | - systemctl is-active erpcore.service && echo "✅ Service running" || echo "❌ Service failed" + # `is-active ... || echo` always exited 0, so a crashed service still reported success. + # Wait a few seconds first: a startup failure (bad or missing connection string) happens + # during MigrateAsync, after systemctl restart has already returned. + sleep 5 + if ! systemctl is-active --quiet erpcore.service; then + echo "❌ erpcore.service is not running:" + journalctl -u erpcore.service -n 50 --no-pager + exit 1 + fi + echo "✅ Service running" build-and-deploy-frontend: name: Build & Deploy Frontend diff --git a/Backend/ERPCore/Program.cs b/Backend/ERPCore/Program.cs index c63ff0d..bb9724c 100644 --- a/Backend/ERPCore/Program.cs +++ b/Backend/ERPCore/Program.cs @@ -36,8 +36,14 @@ builder.Services.AddControllers() // 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."); +// IsNullOrWhiteSpace, not just null: appsettings.json ships the key with an empty value so the +// shape is self-documenting, and each environment supplies the real one. A blank must fail here +// with this message rather than reaching UseMySql, which would report an opaque parse error. +var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); +if (string.IsNullOrWhiteSpace(connectionString)) + throw new InvalidOperationException( + "ConnectionStrings:DefaultConnection is not configured. Set it in appsettings..json " + + "or as the ConnectionStrings__DefaultConnection environment variable."); builder.Services.AddDbContext(o => { diff --git a/Backend/ERPCore/appsettings.json b/Backend/ERPCore/appsettings.json index 4676ad0..8a63040 100644 --- a/Backend/ERPCore/appsettings.json +++ b/Backend/ERPCore/appsettings.json @@ -6,7 +6,7 @@ } }, "ConnectionStrings": { - "DefaultConnection": "Host=localhost;Port=5432;Database=ERPCoreTest;Username=postgres;Password=post@hexdive" + "DefaultConnection": "server=localhost;port=3306;database=erpcore;user=poojathmi;password=poojathmi@hexdive.com" }, "Urls": "http://0.0.0.0:6701", "Auth": {