diff --git a/server/AyaNova/Controllers/LicenseController.cs b/server/AyaNova/Controllers/LicenseController.cs
index e7eeef70..3a0571a7 100644
--- a/server/AyaNova/Controllers/LicenseController.cs
+++ b/server/AyaNova/Controllers/LicenseController.cs
@@ -70,6 +70,26 @@ namespace AyaNova.Api.Controllers
return Ok(ApiOkResponse.Response(ret));
}
+ ///
+ /// Get DB Emptiness
+ ///
+ /// Checks if there is any data in critical tables only
+ [HttpGet("database-empty")]
+ public async Task GetDbEmpty()
+ {
+ if (serverState.IsClosed)
+ {
+ //Exception for SuperUser account to handle licensing issues
+ if (UserIdFromContext.Id(HttpContext.Items) != 1)
+ return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
+ }
+ if (!Authorized.HasReadFullRole(HttpContext.Items, AyaType.License))
+ {
+ return StatusCode(403, new ApiNotAuthorizedResponse());
+ }
+ return Ok(ApiOkResponse.Response(await AyaNova.Util.DbUtil.DBIsEmptyAsync(ct, log)));
+ }
+
@@ -111,7 +131,7 @@ namespace AyaNova.Api.Controllers
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserIdFromContext.Id(HttpContext.Items), 0, AyaType.License, AyaEvent.LicenseFetch), ct);
}
else
- {
+ {
log.LogError($"LicenseController::FetchLicense - failed: {ret}");
}
diff --git a/server/AyaNova/util/DbUtil.cs b/server/AyaNova/util/DbUtil.cs
index a59055f9..9516ed1b 100644
--- a/server/AyaNova/util/DbUtil.cs
+++ b/server/AyaNova/util/DbUtil.cs
@@ -401,7 +401,13 @@ namespace AyaNova.Util
if (await ct.WorkOrder.AnyAsync()) return false;
if (await ct.Quote.AnyAsync()) return false;
if (await ct.PM.AnyAsync()) return false;
-
+ if (await ct.Unit.AnyAsync()) return false;
+ if (await ct.HeadOffice.AnyAsync()) return false;
+ if (await ct.LoanUnit.AnyAsync()) return false;
+ if (await ct.Part.AnyAsync()) return false;
+ if (await ct.Project.AnyAsync()) return false;
+ if (await ct.PurchaseOrder.AnyAsync()) return false;
+
return true;
}