From 59c54ceefeb8df552bc4cc142b25807069553544 Mon Sep 17 00:00:00 2001 From: Jeremy Foster Date: Thu, 1 Aug 2024 09:16:46 -0700 Subject: [PATCH] Improve performance (#137) --- .vscode/launch.json | 8 +- .../Controllers/FileSystemItemController.cs | 9 +- .../Controllers/ServerItemController.cs | 13 +- src/api/Helpers/IXlsExporter.cs | 2 +- src/api/Helpers/XlsExporter.cs | 37 +- src/libs/ches/HSB.Ches.csproj | 4 +- src/libs/css/HSB.CSS.csproj | 4 +- .../dal/Extensions/ModelBuilderExtensions.cs | 2 +- src/libs/dal/HSBContext.cs | 44 +- .../01-FindFileSystemHistoryItemsByMonth.sql | 77 + ...ndFileSystemHistoryItemsByMonthForUser.sql | 82 + .../01-FindServerHistoryItemsByMonth.sql | 74 + ...1-FindServerHistoryItemsByMonthForUser.sql | 81 + .../PostDown/02-vFileSystemHistoryItem.sql | 1 + .../Down/PostDown/02-vServerHistoryItem.sql | 1 + .../Up/PostUp/00-vFileSystemHistoryItem.sql | 28 + .../1.0.4/Up/PostUp/00-vServerHistoryItem.sql | 26 + .../01-FindFileSystemHistoryItemsByMonth.sql | 77 + ...ndFileSystemHistoryItemsByMonthForUser.sql | 82 + .../01-FindServerHistoryItemsByMonth.sql | 74 + ...1-FindServerHistoryItemsByMonthForUser.sql | 81 + .../20240801013229_1.0.4.Designer.cs | 1617 +++++++++++++++++ .../dal/Migrations/20240801013229_1.0.4.cs | 27 + .../dal/Migrations/HSBContextModelSnapshot.cs | 2 +- src/libs/entities/FileSystemHistoryItem.cs | 90 +- .../entities/FileSystemHistoryItemSmall.cs | 101 + src/libs/entities/ServerHistoryItem.cs | 89 +- src/libs/entities/ServerHistoryItemSmall.cs | 100 + src/libs/keycloak/HSB.Keycloak.csproj | 4 +- src/libs/models/FileSystemHistoryItemModel.cs | 25 + src/libs/models/ServerHistoryItemModel.cs | 24 + 31 files changed, 2678 insertions(+), 208 deletions(-) create mode 100644 src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindFileSystemHistoryItemsByMonth.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindFileSystemHistoryItemsByMonthForUser.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindServerHistoryItemsByMonth.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindServerHistoryItemsByMonthForUser.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Down/PostDown/02-vFileSystemHistoryItem.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Down/PostDown/02-vServerHistoryItem.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Up/PostUp/00-vFileSystemHistoryItem.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Up/PostUp/00-vServerHistoryItem.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindFileSystemHistoryItemsByMonth.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindFileSystemHistoryItemsByMonthForUser.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindServerHistoryItemsByMonth.sql create mode 100644 src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindServerHistoryItemsByMonthForUser.sql create mode 100644 src/libs/dal/Migrations/20240801013229_1.0.4.Designer.cs create mode 100644 src/libs/dal/Migrations/20240801013229_1.0.4.cs create mode 100644 src/libs/entities/FileSystemHistoryItemSmall.cs create mode 100644 src/libs/entities/ServerHistoryItemSmall.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 60a9f4c9..4c01cfac 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/src/api/bin/Debug/net7.0/HSB.API.dll", + "program": "${workspaceFolder}/src/api/bin/Debug/net8.0/HSB.API.dll", "args": [], "cwd": "${workspaceFolder}/src/api", "stopAtEntry": false, @@ -35,7 +35,7 @@ "request": "launch", "preLaunchTask": "build-api", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/src/api/bin/Debug/net7.0/HSB.API.dll", + "program": "${workspaceFolder}/src/api/bin/Debug/net8.0/HSB.API.dll", "args": [], "cwd": "${workspaceFolder}/src/api", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console @@ -52,7 +52,7 @@ "request": "launch", "preLaunchTask": "build-api-css", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/src/api-css/bin/Debug/net7.0/HSB.CSS.API.dll", + "program": "${workspaceFolder}/src/api-css/bin/Debug/net8.0/HSB.CSS.API.dll", "args": [], "cwd": "${workspaceFolder}/src/api-css", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console @@ -69,7 +69,7 @@ "request": "launch", "preLaunchTask": "build-data-service", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/src/data-service/bin/Debug/net7.0/HSB.DataService.dll", + "program": "${workspaceFolder}/src/data-service/bin/Debug/net8.0/HSB.DataService.dll", "args": [], "cwd": "${workspaceFolder}/src/data-service", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console diff --git a/src/api/Areas/Dashboard/Controllers/FileSystemItemController.cs b/src/api/Areas/Dashboard/Controllers/FileSystemItemController.cs index ca441d0d..b60be823 100644 --- a/src/api/Areas/Dashboard/Controllers/FileSystemItemController.cs +++ b/src/api/Areas/Dashboard/Controllers/FileSystemItemController.cs @@ -66,7 +66,7 @@ public FileSystemItemController( [HttpGet(Name = "GetFileSystemItems-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "File System Item" })] + [SwaggerOperation(Tags = ["File System Item"])] public IActionResult Find() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -99,7 +99,7 @@ public IActionResult Find() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(FileSystemItemModel), (int)HttpStatusCode.OK)] [ProducesResponseType((int)HttpStatusCode.NoContent)] - [SwaggerOperation(Tags = new[] { "File System Item" })] + [SwaggerOperation(Tags = ["File System Item"])] public IActionResult GetForId(string id) { var isHSB = this.User.HasClientRole(ClientRole.HSB); @@ -128,8 +128,7 @@ public IActionResult GetForId(string id) [HttpGet("history", Name = "GetFileSystemHistoryItems-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "File System Item" })] - // [ResponseCache(VaryByQueryKeys = new[] { "*" }, Location = ResponseCacheLocation.Client, Duration = 1200)] + [SwaggerOperation(Tags = ["File System Item"])] public IActionResult FindHistory() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -166,7 +165,7 @@ public IActionResult FindHistory() [Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "File System Item" })] + [SwaggerOperation(Tags = ["File System Item"])] public IActionResult Export(string format, string name = "service-now") { if (format == "excel") diff --git a/src/api/Areas/Dashboard/Controllers/ServerItemController.cs b/src/api/Areas/Dashboard/Controllers/ServerItemController.cs index 5957fb58..57d5d020 100644 --- a/src/api/Areas/Dashboard/Controllers/ServerItemController.cs +++ b/src/api/Areas/Dashboard/Controllers/ServerItemController.cs @@ -73,8 +73,7 @@ public ServerItemController( [HttpGet(Name = "GetServerItems-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Server Item" })] - // [ResponseCache(VaryByQueryKeys = new[] { "*" }, Location = ResponseCacheLocation.Client, Duration = 60)] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult Find() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -117,7 +116,6 @@ public IActionResult Find() [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] [SwaggerOperation(Tags = new[] { "Server Item" })] - // [ResponseCache(VaryByQueryKeys = new[] { "*" }, Location = ResponseCacheLocation.Client, Duration = 60)] public IActionResult FindList() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -189,8 +187,7 @@ public IActionResult GetForId(string serviceNowKey, bool includeFileSystemItems [HttpGet("history", Name = "GetServerHistoryItems-Dashboard")] [Produces(MediaTypeNames.Application.Json)] [ProducesResponseType(typeof(IEnumerable), (int)HttpStatusCode.OK)] - [SwaggerOperation(Tags = new[] { "Server Item" })] - // [ResponseCache(VaryByQueryKeys = new[] { "*" }, Location = ResponseCacheLocation.Client, Duration = 1200)] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult FindHistory() { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -225,7 +222,7 @@ public IActionResult FindHistory() [Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Server Item" })] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult Export(string format = "excel", string name = "service-now") { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -270,7 +267,7 @@ public IActionResult Export(string format = "excel", string name = "service-now" [Produces("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")] [ProducesResponseType((int)HttpStatusCode.OK)] [ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)] - [SwaggerOperation(Tags = new[] { "Server Item" })] + [SwaggerOperation(Tags = ["Server Item"])] public IActionResult ExportHistory(string format = "excel", string name = "service-now") { var uri = new Uri(this.Request.GetDisplayUrl()); @@ -279,7 +276,7 @@ public IActionResult ExportHistory(string format = "excel", string name = "servi if (format == "excel") { - IEnumerable items; + IEnumerable items; var isHSB = this.User.HasClientRole(ClientRole.HSB); if (isHSB) { diff --git a/src/api/Helpers/IXlsExporter.cs b/src/api/Helpers/IXlsExporter.cs index b26b1566..adbf4d0e 100644 --- a/src/api/Helpers/IXlsExporter.cs +++ b/src/api/Helpers/IXlsExporter.cs @@ -38,6 +38,6 @@ public interface IXlsExporter /// /// /// - XSSFWorkbook GenerateExcel(string sheetName, IEnumerable items); + XSSFWorkbook GenerateExcel(string sheetName, IEnumerable items); #endregion } diff --git a/src/api/Helpers/XlsExporter.cs b/src/api/Helpers/XlsExporter.cs index 3b9a5a6b..e2799dd0 100644 --- a/src/api/Helpers/XlsExporter.cs +++ b/src/api/Helpers/XlsExporter.cs @@ -101,7 +101,7 @@ public XSSFWorkbook GenerateExcel(string sheetName, IEnumerable /// /// - public XSSFWorkbook GenerateExcel(string sheetName, IEnumerable items) + public XSSFWorkbook GenerateExcel(string sheetName, IEnumerable items) { if (items == null) throw new ArgumentNullException(nameof(items)); @@ -192,6 +192,41 @@ private static void AddContent(IWorkbook workbook, IRow row, Entities.ServerHist cell8.CellStyle = numberStyle; cell8.SetCellValue(item.AvailableSpace ?? 0); } + + private static void AddContent(IWorkbook workbook, IRow row, Entities.ServerHistoryItemSmall item) + { + var numberStyle = workbook.CreateCellStyle(); + var numberFormat = workbook.CreateDataFormat().GetFormat("#,#0"); + numberStyle.DataFormat = numberFormat; + + var dateStyle = workbook.CreateCellStyle(); + var dateFormat = workbook.CreateDataFormat().GetFormat("yyyy/MM/dd"); + dateStyle.DataFormat = dateFormat; + + var cell0 = row.CreateCell(0); + cell0.SetCellValue(item.CreatedOn.Date); + cell0.CellStyle = dateStyle; + var cell1 = row.CreateCell(1); + cell1.SetCellValue(item.Tenant?.Code); + var cell2 = row.CreateCell(2); + cell2.SetCellValue(item.Organization?.Code); + var cell3 = row.CreateCell(3); + cell3.SetCellValue(item.Organization?.Name); + var cell4 = row.CreateCell(4); + cell4.SetCellValue(item.ServiceNowKey); + var cell5 = row.CreateCell(5); + cell5.SetCellValue(item.Name); + var cell6 = row.CreateCell(6); + cell6.SetCellValue(item.OperatingSystemItem?.Name); + var cell7 = row.CreateCell(7); + cell7.SetCellType(CellType.Numeric); + cell7.CellStyle = numberStyle; + cell7.SetCellValue(item.Capacity ?? 0); + var cell8 = row.CreateCell(8); + cell8.SetCellType(CellType.Numeric); + cell8.CellStyle = numberStyle; + cell8.SetCellValue(item.AvailableSpace ?? 0); + } #endregion #region Helpers diff --git a/src/libs/ches/HSB.Ches.csproj b/src/libs/ches/HSB.Ches.csproj index 87577a76..dbea91de 100644 --- a/src/libs/ches/HSB.Ches.csproj +++ b/src/libs/ches/HSB.Ches.csproj @@ -13,9 +13,9 @@ - + - + diff --git a/src/libs/css/HSB.CSS.csproj b/src/libs/css/HSB.CSS.csproj index eea2e322..dad2a3bf 100644 --- a/src/libs/css/HSB.CSS.csproj +++ b/src/libs/css/HSB.CSS.csproj @@ -11,12 +11,12 @@ - + - + diff --git a/src/libs/dal/Extensions/ModelBuilderExtensions.cs b/src/libs/dal/Extensions/ModelBuilderExtensions.cs index 72c0172a..93706cfd 100644 --- a/src/libs/dal/Extensions/ModelBuilderExtensions.cs +++ b/src/libs/dal/Extensions/ModelBuilderExtensions.cs @@ -48,7 +48,7 @@ public static ModelBuilder ApplyAllConfigurations(this ModelBuilder modelBuilder var entityConfig = includeContext ? Activator.CreateInstance(config, context) : Activator.CreateInstance(config); var entityType = config.GetInterfaces().First().GetGenericArguments()[0]; var applyConfigurationMethod = method.MakeGenericMethod(entityType); - applyConfigurationMethod.Invoke(modelBuilder, new[] { entityConfig }); + applyConfigurationMethod.Invoke(modelBuilder, [entityConfig]); } } diff --git a/src/libs/dal/HSBContext.cs b/src/libs/dal/HSBContext.cs index baa30de1..56058b43 100644 --- a/src/libs/dal/HSBContext.cs +++ b/src/libs/dal/HSBContext.cs @@ -103,26 +103,48 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.HasDbFunction(typeof(HSBContext) .GetMethod( nameof(FindServerHistoryItemsByMonth), - new[] { typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string) })! - ).HasName("FindServerHistoryItemsByMonth"); - + [typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string)])! + ).HasName(nameof(FindServerHistoryItemsByMonth)); modelBuilder.HasDbFunction(typeof(HSBContext) .GetMethod( nameof(FindServerHistoryItemsByMonthForUser), - new[] { typeof(int), typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string) })! - ).HasName("FindServerHistoryItemsByMonthForUser"); - + [typeof(int), typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string)])! + ).HasName(nameof(FindServerHistoryItemsByMonthForUser)); modelBuilder.HasDbFunction(typeof(HSBContext) .GetMethod( nameof(FindFileSystemHistoryItemsByMonth), - new[] { typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string) })!) - .HasName("FindFileSystemHistoryItemsByMonth"); - + [typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string)])! + ).HasName(nameof(FindFileSystemHistoryItemsByMonth)); modelBuilder.HasDbFunction(typeof(HSBContext) .GetMethod( nameof(FindFileSystemHistoryItemsByMonthForUser), - new[] { typeof(int), typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string) })!) - .HasName("FindFileSystemHistoryItemsByMonthForUser"); + [typeof(int), typeof(DateTime), typeof(DateTime?), typeof(int?), typeof(int?), typeof(int?), typeof(string)])! + ).HasName(nameof(FindFileSystemHistoryItemsByMonthForUser)); + + // modelBuilder.Entity().ToTable((string?)null); + // modelBuilder.Entity().ToTable((string?)null); + // modelBuilder.Entity().ToTable((string?)null); + // modelBuilder.Entity().ToTable((string?)null); + + // modelBuilder.Ignore(); + // modelBuilder.Ignore(); + // modelBuilder.Ignore(); + // modelBuilder.Ignore(); + + // modelBuilder.Entity().ToView("vServerHistoryItem").HasKey(m => m.Id); + // modelBuilder.Entity().ToView("vServerHistoryItem").HasKey(m => m.Id); + // modelBuilder.Entity().ToView("vFileSystemHistoryItem").HasKey(m => m.Id); + // modelBuilder.Entity().ToView("vFileSystemHistoryItem").HasKey(m => m.Id); + + // modelBuilder.Entity().HasNoKey().ToSqlQuery("SELECT * FROM public.vServerHistoryItem"); + // modelBuilder.Entity().HasNoKey().ToSqlQuery("SELECT * FROM public.vServerHistoryItem"); + // modelBuilder.Entity().HasNoKey().ToSqlQuery("SELECT * FROM public.vFileSystemHistoryItem"); + // modelBuilder.Entity().HasNoKey().ToSqlQuery("SELECT * FROM public.vFileSystemHistoryItem"); + + // modelBuilder.Entity().ToFunction(nameof(FindServerHistoryItemsByMonth)); + // modelBuilder.Entity().ToFunction(nameof(FindServerHistoryItemsByMonthForUser)); + // modelBuilder.Entity().ToFunction(nameof(FindFileSystemHistoryItemsByMonth)); + // modelBuilder.Entity().ToFunction(nameof(FindFileSystemHistoryItemsByMonthForUser)); } /// diff --git a/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindFileSystemHistoryItemsByMonth.sql b/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindFileSystemHistoryItemsByMonth.sql new file mode 100644 index 00000000..11ca0849 --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindFileSystemHistoryItemsByMonth.sql @@ -0,0 +1,77 @@ +DROP FUNCTION "FindFileSystemHistoryItemsByMonth"; + +CREATE OR REPLACE FUNCTION "FindFileSystemHistoryItemsByMonth"( + "startDate" TIMESTAMPTZ + , "endDate" TIMESTAMPTZ DEFAULT NULL + , "tenantId" INT DEFAULT NULL + , "organizationId" INT DEFAULT NULL + , "operatingSystemItemId" INT DEFAULT NULL + , "serverServiceNowKey" VARCHAR(200) DEFAULT NULL +) +RETURNS SETOF public."FileSystemHistoryItem" +LANGUAGE plpgsql +AS $$ +DECLARE + end_date_default TIMESTAMPTZ; + last_month_start TIMESTAMPTZ; +BEGIN + end_date_default := (SELECT COALESCE($2, NOW())); + last_month_start := (SELECT (DATE_TRUNC('month', end_date_default))::TIMESTAMPTZ); + RETURN QUERY + SELECT DISTINCT + "Id" + , "ServiceNowKey" + , "RawData" + , "RawDataCI" + , "Name" + , "Label" + , "Category" + , "Subcategory" + , "StorageType" + , "MediaType" + , "VolumeId" + , "ClassName" + , "Capacity" + , "DiskSpace" + , "Size" + , "SizeBytes" + , "UsedSizeBytes" + , "AvailableSpace" + , "FreeSpace" + , "FreeSpaceBytes" + , "CreatedOn" + , "CreatedBy" + , "UpdatedOn" + , "UpdatedBy" + , "Version" + , "ServerItemServiceNowKey" + , "InstallStatus" + FROM ( + SELECT fshi.* + , ROW_NUMBER() OVER (PARTITION BY fshi."ServiceNowKey", EXTRACT(YEAR FROM fshi."CreatedOn"), EXTRACT(MONTH FROM fshi."CreatedOn") ORDER BY fshi."CreatedOn" DESC) AS "rn" + FROM public."FileSystemHistoryItem" AS fshi + JOIN public."FileSystemItem" AS fsi ON fshi."ServiceNowKey" = fsi."ServiceNowKey" + JOIN public."ServerItem" AS si ON fsi."ServerItemServiceNowKey" = si."ServiceNowKey" + WHERE fshi."CreatedOn" >= $1 + AND fshi."CreatedOn" < last_month_start + AND ($3 IS NULL OR si."TenantId" = $3) + AND ($4 IS NULL OR si."OrganizationId" = $4) + AND ($5 IS NULL OR si."OperatingSystemItemId" = $5) + AND ($6 IS NULL OR fshi."ServerItemServiceNowKey" = $6) + UNION + SELECT fshi.* + , ROW_NUMBER() OVER (PARTITION BY fshi."ServiceNowKey", EXTRACT(YEAR FROM fshi."CreatedOn"), EXTRACT(MONTH FROM fshi."CreatedOn") ORDER BY fshi."CreatedOn" DESC) AS "rn" + FROM public."FileSystemHistoryItem" AS fshi + JOIN public."FileSystemItem" AS fsi ON fshi."ServiceNowKey" = fsi."ServiceNowKey" + JOIN public."ServerItem" AS si ON fsi."ServerItemServiceNowKey" = si."ServiceNowKey" + WHERE fshi."InstallStatus" = 1 + AND fshi."CreatedOn" >= last_month_start + AND ($2 IS NULL OR fshi."CreatedOn" <= $2) + AND ($3 IS NULL OR si."TenantId" = $3) + AND ($4 IS NULL OR si."OrganizationId" = $4) + AND ($5 IS NULL OR si."OperatingSystemItemId" = $5) + AND ($6 IS NULL OR fshi."ServerItemServiceNowKey" = $6) + ) AS "sub" + WHERE "rn" = 1 + ORDER BY "ServiceNowKey", "CreatedOn"; +END;$$ diff --git a/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindFileSystemHistoryItemsByMonthForUser.sql b/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindFileSystemHistoryItemsByMonthForUser.sql new file mode 100644 index 00000000..4ebca908 --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindFileSystemHistoryItemsByMonthForUser.sql @@ -0,0 +1,82 @@ +DROP FUNCTION "FindFileSystemHistoryItemsByMonthForUser"; + +CREATE OR REPLACE FUNCTION "FindFileSystemHistoryItemsByMonthForUser"( + "userId" INT + , "startDate" TIMESTAMPTZ + , "endDate" TIMESTAMPTZ DEFAULT NULL + , "tenantId" INT DEFAULT NULL + , "organizationId" INT DEFAULT NULL + , "operatingSystemItemId" INT DEFAULT NULL + , "serverServiceNowKey" VARCHAR(200) DEFAULT NULL +) +RETURNS SETOF public."FileSystemHistoryItem" +LANGUAGE plpgsql +AS $$ +DECLARE + end_date_default TIMESTAMPTZ; + last_month_start TIMESTAMPTZ; +BEGIN + end_date_default := (SELECT COALESCE($3, NOW())); + last_month_start := (SELECT (DATE_TRUNC('month', end_date_default))::TIMESTAMPTZ); + RETURN QUERY + SELECT DISTINCT + "Id" + , "ServiceNowKey" + , "RawData" + , "RawDataCI" + , "Name" + , "Label" + , "Category" + , "Subcategory" + , "StorageType" + , "MediaType" + , "VolumeId" + , "ClassName" + , "Capacity" + , "DiskSpace" + , "Size" + , "SizeBytes" + , "UsedSizeBytes" + , "AvailableSpace" + , "FreeSpace" + , "FreeSpaceBytes" + , "CreatedOn" + , "CreatedBy" + , "UpdatedOn" + , "UpdatedBy" + , "Version" + , "ServerItemServiceNowKey" + , "InstallStatus" + FROM ( + SELECT fshi.* + , ROW_NUMBER() OVER (PARTITION BY fshi."ServiceNowKey", EXTRACT(YEAR FROM fshi."CreatedOn"), EXTRACT(MONTH FROM fshi."CreatedOn") ORDER BY fshi."CreatedOn" DESC) AS "rn" + FROM public."FileSystemHistoryItem" AS fshi + JOIN public."FileSystemItem" AS fsi ON fshi."ServiceNowKey" = fsi."ServiceNowKey" + JOIN public."ServerItem" AS si ON fsi."ServerItemServiceNowKey" = si."ServiceNowKey" + WHERE fshi."CreatedOn" >= $2 + AND fshi."CreatedOn" < last_month_start + AND ($4 IS NULL OR si."TenantId" = $4) + AND ($5 IS NULL OR si."OrganizationId" = $5) + AND ($6 IS NULL OR si."OperatingSystemItemId" = $6) + AND ($7 IS NULL OR fshi."ServerItemServiceNowKey" = $7) + AND (si."TenantId" IN (SELECT "TenantId" FROM public."UserTenant" WHERE "UserId" = $1) + OR si."OrganizationId" IN (SELECT "OrganizationId" FROM public."UserOrganization" WHERE "UserId" = $1)) + UNION + SELECT fshi.* + , ROW_NUMBER() OVER (PARTITION BY fshi."ServiceNowKey", EXTRACT(YEAR FROM fshi."CreatedOn"), EXTRACT(MONTH FROM fshi."CreatedOn") ORDER BY fshi."CreatedOn" DESC) AS "rn" + FROM public."FileSystemHistoryItem" AS fshi + JOIN public."FileSystemItem" AS fsi ON fshi."ServiceNowKey" = fsi."ServiceNowKey" + JOIN public."ServerItem" AS si ON fsi."ServerItemServiceNowKey" = si."ServiceNowKey" + WHERE fshi."InstallStatus" = 1 + AND fshi."CreatedOn" >= last_month_start + AND ($3 IS NULL OR fshi."CreatedOn" <= $3) + AND ($4 IS NULL OR si."TenantId" = $4) + AND ($5 IS NULL OR si."OrganizationId" = $5) + AND ($6 IS NULL OR si."OperatingSystemItemId" = $6) + AND ($7 IS NULL OR fshi."ServerItemServiceNowKey" = $7) + AND (si."TenantId" IN (SELECT "TenantId" FROM public."UserTenant" WHERE "UserId" = $1) + OR si."OrganizationId" IN (SELECT "OrganizationId" FROM public."UserOrganization" WHERE "UserId" = $1)) + ) AS "sub" + WHERE "rn" = 1 + ORDER BY "ServiceNowKey", "CreatedOn"; +END;$$ diff --git a/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindServerHistoryItemsByMonth.sql b/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindServerHistoryItemsByMonth.sql new file mode 100644 index 00000000..7bf63fe9 --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindServerHistoryItemsByMonth.sql @@ -0,0 +1,74 @@ +DROP FUNCTION "FindServerHistoryItemsByMonth"; + +CREATE OR REPLACE FUNCTION "FindServerHistoryItemsByMonth"( + "startDate" TIMESTAMPTZ + , "endDate" TIMESTAMPTZ DEFAULT NULL + , "tenantId" INT DEFAULT NULL + , "organizationId" INT DEFAULT NULL + , "operatingSystemItemId" INT DEFAULT NULL + , "serviceNowKey" VARCHAR(200) DEFAULT NULL +) +RETURNS SETOF public."ServerHistoryItem" +LANGUAGE plpgsql +AS $$ +DECLARE + end_date_default TIMESTAMPTZ; + last_month_start TIMESTAMPTZ; +BEGIN + end_date_default := (SELECT COALESCE($2, NOW())); + last_month_start := (SELECT (DATE_TRUNC('month', end_date_default))::TIMESTAMPTZ); + RETURN QUERY + SELECT DISTINCT + "Id" + , "TenantId" + , "OrganizationId" + , "OperatingSystemItemId" + , "ServiceNowKey" + , "HistoryKey" + , "RawData" + , "RawDataCI" + , "ClassName" + , "Name" + , "Category" + , "Subcategory" + , "DnsDomain" + , "Platform" + , "IPAddress" + , "FQDN" + , "DiskSpace" + , "Capacity" + , "AvailableSpace" + , "CreatedOn" + , "CreatedBy" + , "UpdatedOn" + , "UpdatedBy" + , "Version" + , "InstallStatus" + FROM ( + SELECT * + , ROW_NUMBER() OVER (PARTITION BY "ServiceNowKey", EXTRACT(YEAR FROM "CreatedOn"), EXTRACT(MONTH FROM "CreatedOn") ORDER BY "CreatedOn" DESC) AS "rn" + FROM public."ServerHistoryItem" + WHERE "CreatedOn" >= $1 + AND "CreatedOn" < last_month_start + AND ($3 IS NULL OR "TenantId" = $3) + AND ($4 IS NULL OR "OrganizationId" = $4) + AND ($5 IS NULL OR "OperatingSystemItemId" = $5) + AND ($6 IS NULL OR "ServiceNowKey" = $6) + UNION + SELECT * + , ROW_NUMBER() OVER (PARTITION BY "ServiceNowKey", EXTRACT(YEAR FROM "CreatedOn"), EXTRACT(MONTH FROM "CreatedOn") ORDER BY "CreatedOn" DESC) AS "rn" + FROM public."ServerHistoryItem" + WHERE "InstallStatus" = 1 + AND "CreatedOn" >= last_month_start + AND ($2 IS NULL OR "CreatedOn" <= $2) + AND ($3 IS NULL OR "TenantId" = $3) + AND ($4 IS NULL OR "OrganizationId" = $4) + AND ($5 IS NULL OR "OperatingSystemItemId" = $5) + AND ($6 IS NULL OR "ServiceNowKey" = $6) + ) AS "sub" + WHERE "rn" = 1 + ORDER BY "ServiceNowKey", "CreatedOn"; +END;$$ + +-- Use by calling +-- select * from public."FindServerHistoryItemsByMonth"('2023-12-01'); diff --git a/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindServerHistoryItemsByMonthForUser.sql b/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindServerHistoryItemsByMonthForUser.sql new file mode 100644 index 00000000..b90e3038 --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Down/PostDown/01-FindServerHistoryItemsByMonthForUser.sql @@ -0,0 +1,81 @@ +DROP FUNCTION "FindServerHistoryItemsByMonthForUser"; + +CREATE OR REPLACE FUNCTION "FindServerHistoryItemsByMonthForUser"( + "userId" INT + , "startDate" TIMESTAMPTZ + , "endDate" TIMESTAMPTZ DEFAULT NULL + , "tenantId" INT DEFAULT NULL + , "organizationId" INT DEFAULT NULL + , "operatingSystemItemId" INT DEFAULT NULL + , "serviceNowKey" VARCHAR(200) DEFAULT NULL +) +RETURNS SETOF public."ServerHistoryItem" +LANGUAGE plpgsql +AS $$ +DECLARE + end_date_default TIMESTAMPTZ; + last_month_start TIMESTAMPTZ; +BEGIN + end_date_default := (SELECT COALESCE($3, NOW())); + last_month_start := (SELECT (DATE_TRUNC('month', end_date_default))::TIMESTAMPTZ); + RETURN QUERY + SELECT DISTINCT + "Id" + , "TenantId" + , "OrganizationId" + , "OperatingSystemItemId" + , "ServiceNowKey" + , "HistoryKey" + , "RawData" + , "RawDataCI" + , "ClassName" + , "Name" + , "Category" + , "Subcategory" + , "DnsDomain" + , "Platform" + , "IPAddress" + , "FQDN" + , "DiskSpace" + , "Capacity" + , "AvailableSpace" + , "CreatedOn" + , "CreatedBy" + , "UpdatedOn" + , "UpdatedBy" + , "Version" + , "InstallStatus" + FROM ( + SELECT shi.* + , ROW_NUMBER() OVER (PARTITION BY shi."ServiceNowKey", EXTRACT(YEAR FROM shi."CreatedOn"), EXTRACT(MONTH FROM shi."CreatedOn") ORDER BY shi."CreatedOn" DESC) AS "rn" + FROM public."ServerHistoryItem" shi + JOIN public."ServerItem" si ON shi."ServiceNowKey" = si."ServiceNowKey" + WHERE shi."CreatedOn" >= $2 + AND shi."CreatedOn" < last_month_start + AND ($4 IS NULL OR shi."TenantId" = $4) + AND ($5 IS NULL OR shi."OrganizationId" = $5) + AND ($6 IS NULL OR shi."OperatingSystemItemId" = $6) + AND ($7 IS NULL OR shi."ServiceNowKey" = $7) + AND (si."TenantId" IN (SELECT "TenantId" FROM public."UserTenant" WHERE "UserId" = $1) + OR si."OrganizationId" IN (SELECT "OrganizationId" FROM public."UserOrganization" WHERE "UserId" = $1)) + UNION + SELECT shi.* + , ROW_NUMBER() OVER (PARTITION BY shi."ServiceNowKey", EXTRACT(YEAR FROM shi."CreatedOn"), EXTRACT(MONTH FROM shi."CreatedOn") ORDER BY shi."CreatedOn" DESC) AS "rn" + FROM public."ServerHistoryItem" shi + JOIN public."ServerItem" si ON shi."ServiceNowKey" = si."ServiceNowKey" + WHERE shi."InstallStatus" = 1 + AND shi."CreatedOn" >= last_month_start + AND ($3 IS NULL OR shi."CreatedOn" <= $3) + AND ($4 IS NULL OR shi."TenantId" = $4) + AND ($5 IS NULL OR shi."OrganizationId" = $5) + AND ($6 IS NULL OR shi."OperatingSystemItemId" = $6) + AND ($7 IS NULL OR shi."ServiceNowKey" = $7) + AND (si."TenantId" IN (SELECT "TenantId" FROM public."UserTenant" WHERE "UserId" = $1) + OR si."OrganizationId" IN (SELECT "OrganizationId" FROM public."UserOrganization" WHERE "UserId" = $1)) + ) AS "sub" + WHERE "rn" = 1 + ORDER BY "ServiceNowKey", "CreatedOn"; +END;$$ + +-- Use by calling +-- select * from public."FindServerHistoryItemsByMonthForUser"(1, '2023-12-01'); diff --git a/src/libs/dal/Migrations/1.0.4/Down/PostDown/02-vFileSystemHistoryItem.sql b/src/libs/dal/Migrations/1.0.4/Down/PostDown/02-vFileSystemHistoryItem.sql new file mode 100644 index 00000000..6e49be23 --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Down/PostDown/02-vFileSystemHistoryItem.sql @@ -0,0 +1 @@ +DROP VIEW IF EXISTS "vFileSystemHistoryItem"; diff --git a/src/libs/dal/Migrations/1.0.4/Down/PostDown/02-vServerHistoryItem.sql b/src/libs/dal/Migrations/1.0.4/Down/PostDown/02-vServerHistoryItem.sql new file mode 100644 index 00000000..eeea4e19 --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Down/PostDown/02-vServerHistoryItem.sql @@ -0,0 +1 @@ +DROP VIEW IF EXISTS "vServerHistoryItem"; diff --git a/src/libs/dal/Migrations/1.0.4/Up/PostUp/00-vFileSystemHistoryItem.sql b/src/libs/dal/Migrations/1.0.4/Up/PostUp/00-vFileSystemHistoryItem.sql new file mode 100644 index 00000000..881812ed --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Up/PostUp/00-vFileSystemHistoryItem.sql @@ -0,0 +1,28 @@ +CREATE OR REPLACE VIEW "vFileSystemHistoryItem" AS +SELECT + "Id" + , "ServiceNowKey" + , "Name" + , "Label" + , "Category" + , "Subcategory" + , "StorageType" + , "MediaType" + , "VolumeId" + , "ClassName" + , "Capacity" + , "DiskSpace" + , "Size" + , "SizeBytes" + , "UsedSizeBytes" + , "AvailableSpace" + , "FreeSpace" + , "FreeSpaceBytes" + , "CreatedOn" + , "CreatedBy" + , "UpdatedOn" + , "UpdatedBy" + , "Version" + , "ServerItemServiceNowKey" + , "InstallStatus" +FROM public."FileSystemHistoryItem"; diff --git a/src/libs/dal/Migrations/1.0.4/Up/PostUp/00-vServerHistoryItem.sql b/src/libs/dal/Migrations/1.0.4/Up/PostUp/00-vServerHistoryItem.sql new file mode 100644 index 00000000..1a2a99a3 --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Up/PostUp/00-vServerHistoryItem.sql @@ -0,0 +1,26 @@ +CREATE OR REPLACE VIEW "vServerHistoryItem" AS +SELECT + "Id" + , "TenantId" + , "OrganizationId" + , "OperatingSystemItemId" + , "ServiceNowKey" + , "HistoryKey" + , "ClassName" + , "Name" + , "Category" + , "Subcategory" + , "DnsDomain" + , "Platform" + , "IPAddress" + , "FQDN" + , "DiskSpace" + , "Capacity" + , "AvailableSpace" + , "CreatedOn" + , "CreatedBy" + , "UpdatedOn" + , "UpdatedBy" + , "Version" + , "InstallStatus" +FROM public."ServerHistoryItem"; diff --git a/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindFileSystemHistoryItemsByMonth.sql b/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindFileSystemHistoryItemsByMonth.sql new file mode 100644 index 00000000..5a8113b5 --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindFileSystemHistoryItemsByMonth.sql @@ -0,0 +1,77 @@ +DROP FUNCTION "FindFileSystemHistoryItemsByMonth"; + +CREATE OR REPLACE FUNCTION "FindFileSystemHistoryItemsByMonth"( + "startDate" TIMESTAMPTZ + , "endDate" TIMESTAMPTZ DEFAULT NULL + , "tenantId" INT DEFAULT NULL + , "organizationId" INT DEFAULT NULL + , "operatingSystemItemId" INT DEFAULT NULL + , "serverServiceNowKey" VARCHAR(200) DEFAULT NULL +) +RETURNS SETOF public."FileSystemHistoryItem" +LANGUAGE plpgsql +AS $$ +DECLARE + end_date_default TIMESTAMPTZ; + last_month_start TIMESTAMPTZ; +BEGIN + end_date_default := (SELECT COALESCE($2, NOW())); + last_month_start := (SELECT (DATE_TRUNC('month', end_date_default))::TIMESTAMPTZ); + RETURN QUERY + SELECT DISTINCT + "Id" + , "ServiceNowKey" + , '{}'::jsonb AS "RawData" + , '{}'::jsonb AS "RawDataCI" + , "Name" + , "Label" + , "Category" + , "Subcategory" + , "StorageType" + , "MediaType" + , "VolumeId" + , "ClassName" + , "Capacity" + , "DiskSpace" + , "Size" + , "SizeBytes" + , "UsedSizeBytes" + , "AvailableSpace" + , "FreeSpace" + , "FreeSpaceBytes" + , "CreatedOn" + , "CreatedBy" + , "UpdatedOn" + , "UpdatedBy" + , "Version" + , "ServerItemServiceNowKey" + , "InstallStatus" + FROM ( + SELECT fshi.* + , ROW_NUMBER() OVER (PARTITION BY fshi."ServiceNowKey", EXTRACT(YEAR FROM fshi."CreatedOn"), EXTRACT(MONTH FROM fshi."CreatedOn") ORDER BY fshi."CreatedOn" DESC) AS "rn" + FROM public."FileSystemHistoryItem" AS fshi + JOIN public."FileSystemItem" AS fsi ON fshi."ServiceNowKey" = fsi."ServiceNowKey" + JOIN public."ServerItem" AS si ON fsi."ServerItemServiceNowKey" = si."ServiceNowKey" + WHERE fshi."CreatedOn" >= $1 + AND fshi."CreatedOn" < last_month_start + AND ($3 IS NULL OR si."TenantId" = $3) + AND ($4 IS NULL OR si."OrganizationId" = $4) + AND ($5 IS NULL OR si."OperatingSystemItemId" = $5) + AND ($6 IS NULL OR fshi."ServerItemServiceNowKey" = $6) + UNION + SELECT fshi.* + , ROW_NUMBER() OVER (PARTITION BY fshi."ServiceNowKey", EXTRACT(YEAR FROM fshi."CreatedOn"), EXTRACT(MONTH FROM fshi."CreatedOn") ORDER BY fshi."CreatedOn" DESC) AS "rn" + FROM public."FileSystemHistoryItem" AS fshi + JOIN public."FileSystemItem" AS fsi ON fshi."ServiceNowKey" = fsi."ServiceNowKey" + JOIN public."ServerItem" AS si ON fsi."ServerItemServiceNowKey" = si."ServiceNowKey" + WHERE fshi."InstallStatus" = 1 + AND fshi."CreatedOn" >= last_month_start + AND ($2 IS NULL OR fshi."CreatedOn" <= $2) + AND ($3 IS NULL OR si."TenantId" = $3) + AND ($4 IS NULL OR si."OrganizationId" = $4) + AND ($5 IS NULL OR si."OperatingSystemItemId" = $5) + AND ($6 IS NULL OR fshi."ServerItemServiceNowKey" = $6) + ) AS "sub" + WHERE "rn" = 1 + ORDER BY "ServiceNowKey", "CreatedOn"; +END;$$ diff --git a/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindFileSystemHistoryItemsByMonthForUser.sql b/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindFileSystemHistoryItemsByMonthForUser.sql new file mode 100644 index 00000000..7740f11c --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindFileSystemHistoryItemsByMonthForUser.sql @@ -0,0 +1,82 @@ +DROP FUNCTION "FindFileSystemHistoryItemsByMonthForUser"; + +CREATE OR REPLACE FUNCTION "FindFileSystemHistoryItemsByMonthForUser"( + "userId" INT + , "startDate" TIMESTAMPTZ + , "endDate" TIMESTAMPTZ DEFAULT NULL + , "tenantId" INT DEFAULT NULL + , "organizationId" INT DEFAULT NULL + , "operatingSystemItemId" INT DEFAULT NULL + , "serverServiceNowKey" VARCHAR(200) DEFAULT NULL +) +RETURNS SETOF public."FileSystemHistoryItem" +LANGUAGE plpgsql +AS $$ +DECLARE + end_date_default TIMESTAMPTZ; + last_month_start TIMESTAMPTZ; +BEGIN + end_date_default := (SELECT COALESCE($3, NOW())); + last_month_start := (SELECT (DATE_TRUNC('month', end_date_default))::TIMESTAMPTZ); + RETURN QUERY + SELECT DISTINCT + "Id" + , "ServiceNowKey" + , '{}'::jsonb AS "RawData" + , '{}'::jsonb AS "RawDataCI" + , "Name" + , "Label" + , "Category" + , "Subcategory" + , "StorageType" + , "MediaType" + , "VolumeId" + , "ClassName" + , "Capacity" + , "DiskSpace" + , "Size" + , "SizeBytes" + , "UsedSizeBytes" + , "AvailableSpace" + , "FreeSpace" + , "FreeSpaceBytes" + , "CreatedOn" + , "CreatedBy" + , "UpdatedOn" + , "UpdatedBy" + , "Version" + , "ServerItemServiceNowKey" + , "InstallStatus" + FROM ( + SELECT fshi.* + , ROW_NUMBER() OVER (PARTITION BY fshi."ServiceNowKey", EXTRACT(YEAR FROM fshi."CreatedOn"), EXTRACT(MONTH FROM fshi."CreatedOn") ORDER BY fshi."CreatedOn" DESC) AS "rn" + FROM public."FileSystemHistoryItem" AS fshi + JOIN public."FileSystemItem" AS fsi ON fshi."ServiceNowKey" = fsi."ServiceNowKey" + JOIN public."ServerItem" AS si ON fsi."ServerItemServiceNowKey" = si."ServiceNowKey" + WHERE fshi."CreatedOn" >= $2 + AND fshi."CreatedOn" < last_month_start + AND ($4 IS NULL OR si."TenantId" = $4) + AND ($5 IS NULL OR si."OrganizationId" = $5) + AND ($6 IS NULL OR si."OperatingSystemItemId" = $6) + AND ($7 IS NULL OR fshi."ServerItemServiceNowKey" = $7) + AND (si."TenantId" IN (SELECT "TenantId" FROM public."UserTenant" WHERE "UserId" = $1) + OR si."OrganizationId" IN (SELECT "OrganizationId" FROM public."UserOrganization" WHERE "UserId" = $1)) + UNION + SELECT fshi.* + , ROW_NUMBER() OVER (PARTITION BY fshi."ServiceNowKey", EXTRACT(YEAR FROM fshi."CreatedOn"), EXTRACT(MONTH FROM fshi."CreatedOn") ORDER BY fshi."CreatedOn" DESC) AS "rn" + FROM public."FileSystemHistoryItem" AS fshi + JOIN public."FileSystemItem" AS fsi ON fshi."ServiceNowKey" = fsi."ServiceNowKey" + JOIN public."ServerItem" AS si ON fsi."ServerItemServiceNowKey" = si."ServiceNowKey" + WHERE fshi."InstallStatus" = 1 + AND fshi."CreatedOn" >= last_month_start + AND ($3 IS NULL OR fshi."CreatedOn" <= $3) + AND ($4 IS NULL OR si."TenantId" = $4) + AND ($5 IS NULL OR si."OrganizationId" = $5) + AND ($6 IS NULL OR si."OperatingSystemItemId" = $6) + AND ($7 IS NULL OR fshi."ServerItemServiceNowKey" = $7) + AND (si."TenantId" IN (SELECT "TenantId" FROM public."UserTenant" WHERE "UserId" = $1) + OR si."OrganizationId" IN (SELECT "OrganizationId" FROM public."UserOrganization" WHERE "UserId" = $1)) + ) AS "sub" + WHERE "rn" = 1 + ORDER BY "ServiceNowKey", "CreatedOn"; +END;$$ diff --git a/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindServerHistoryItemsByMonth.sql b/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindServerHistoryItemsByMonth.sql new file mode 100644 index 00000000..9834ff64 --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindServerHistoryItemsByMonth.sql @@ -0,0 +1,74 @@ +DROP FUNCTION "FindServerHistoryItemsByMonth"; + +CREATE OR REPLACE FUNCTION "FindServerHistoryItemsByMonth"( + "startDate" TIMESTAMPTZ + , "endDate" TIMESTAMPTZ DEFAULT NULL + , "tenantId" INT DEFAULT NULL + , "organizationId" INT DEFAULT NULL + , "operatingSystemItemId" INT DEFAULT NULL + , "serviceNowKey" VARCHAR(200) DEFAULT NULL +) +RETURNS SETOF public."ServerHistoryItem" +LANGUAGE plpgsql +AS $$ +DECLARE + end_date_default TIMESTAMPTZ; + last_month_start TIMESTAMPTZ; +BEGIN + end_date_default := (SELECT COALESCE($2, NOW())); + last_month_start := (SELECT (DATE_TRUNC('month', end_date_default))::TIMESTAMPTZ); + RETURN QUERY + SELECT DISTINCT + "Id" + , "TenantId" + , "OrganizationId" + , "OperatingSystemItemId" + , "ServiceNowKey" + , "HistoryKey" + , '{}'::jsonb AS "RawData" + , '{}'::jsonb AS "RawDataCI" + , "ClassName" + , "Name" + , "Category" + , "Subcategory" + , "DnsDomain" + , "Platform" + , "IPAddress" + , "FQDN" + , "DiskSpace" + , "Capacity" + , "AvailableSpace" + , "CreatedOn" + , "CreatedBy" + , "UpdatedOn" + , "UpdatedBy" + , "Version" + , "InstallStatus" + FROM ( + SELECT * + , ROW_NUMBER() OVER (PARTITION BY "ServiceNowKey", EXTRACT(YEAR FROM "CreatedOn"), EXTRACT(MONTH FROM "CreatedOn") ORDER BY "CreatedOn" DESC) AS "rn" + FROM public."ServerHistoryItem" + WHERE "CreatedOn" >= $1 + AND "CreatedOn" < last_month_start + AND ($3 IS NULL OR "TenantId" = $3) + AND ($4 IS NULL OR "OrganizationId" = $4) + AND ($5 IS NULL OR "OperatingSystemItemId" = $5) + AND ($6 IS NULL OR "ServiceNowKey" = $6) + UNION + SELECT * + , ROW_NUMBER() OVER (PARTITION BY "ServiceNowKey", EXTRACT(YEAR FROM "CreatedOn"), EXTRACT(MONTH FROM "CreatedOn") ORDER BY "CreatedOn" DESC) AS "rn" + FROM public."ServerHistoryItem" + WHERE "InstallStatus" = 1 + AND "CreatedOn" >= last_month_start + AND ($2 IS NULL OR "CreatedOn" <= $2) + AND ($3 IS NULL OR "TenantId" = $3) + AND ($4 IS NULL OR "OrganizationId" = $4) + AND ($5 IS NULL OR "OperatingSystemItemId" = $5) + AND ($6 IS NULL OR "ServiceNowKey" = $6) + ) AS "sub" + WHERE "rn" = 1 + ORDER BY "ServiceNowKey", "CreatedOn"; +END;$$ + +-- Use by calling +-- select * from public."FindServerHistoryItemsByMonth"('2023-12-01'); diff --git a/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindServerHistoryItemsByMonthForUser.sql b/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindServerHistoryItemsByMonthForUser.sql new file mode 100644 index 00000000..a048771a --- /dev/null +++ b/src/libs/dal/Migrations/1.0.4/Up/PostUp/01-FindServerHistoryItemsByMonthForUser.sql @@ -0,0 +1,81 @@ +DROP FUNCTION "FindServerHistoryItemsByMonthForUser"; + +CREATE OR REPLACE FUNCTION "FindServerHistoryItemsByMonthForUser"( + "userId" INT + , "startDate" TIMESTAMPTZ + , "endDate" TIMESTAMPTZ DEFAULT NULL + , "tenantId" INT DEFAULT NULL + , "organizationId" INT DEFAULT NULL + , "operatingSystemItemId" INT DEFAULT NULL + , "serviceNowKey" VARCHAR(200) DEFAULT NULL +) +RETURNS SETOF public."ServerHistoryItem" +LANGUAGE plpgsql +AS $$ +DECLARE + end_date_default TIMESTAMPTZ; + last_month_start TIMESTAMPTZ; +BEGIN + end_date_default := (SELECT COALESCE($3, NOW())); + last_month_start := (SELECT (DATE_TRUNC('month', end_date_default))::TIMESTAMPTZ); + RETURN QUERY + SELECT DISTINCT + "Id" + , "TenantId" + , "OrganizationId" + , "OperatingSystemItemId" + , "ServiceNowKey" + , "HistoryKey" + , '{}'::jsonb AS "RawData" + , '{}'::jsonb AS "RawDataCI" + , "ClassName" + , "Name" + , "Category" + , "Subcategory" + , "DnsDomain" + , "Platform" + , "IPAddress" + , "FQDN" + , "DiskSpace" + , "Capacity" + , "AvailableSpace" + , "CreatedOn" + , "CreatedBy" + , "UpdatedOn" + , "UpdatedBy" + , "Version" + , "InstallStatus" + FROM ( + SELECT shi.* + , ROW_NUMBER() OVER (PARTITION BY shi."ServiceNowKey", EXTRACT(YEAR FROM shi."CreatedOn"), EXTRACT(MONTH FROM shi."CreatedOn") ORDER BY shi."CreatedOn" DESC) AS "rn" + FROM public."ServerHistoryItem" shi + JOIN public."ServerItem" si ON shi."ServiceNowKey" = si."ServiceNowKey" + WHERE shi."CreatedOn" >= $2 + AND shi."CreatedOn" < last_month_start + AND ($4 IS NULL OR shi."TenantId" = $4) + AND ($5 IS NULL OR shi."OrganizationId" = $5) + AND ($6 IS NULL OR shi."OperatingSystemItemId" = $6) + AND ($7 IS NULL OR shi."ServiceNowKey" = $7) + AND (si."TenantId" IN (SELECT "TenantId" FROM public."UserTenant" WHERE "UserId" = $1) + OR si."OrganizationId" IN (SELECT "OrganizationId" FROM public."UserOrganization" WHERE "UserId" = $1)) + UNION + SELECT shi.* + , ROW_NUMBER() OVER (PARTITION BY shi."ServiceNowKey", EXTRACT(YEAR FROM shi."CreatedOn"), EXTRACT(MONTH FROM shi."CreatedOn") ORDER BY shi."CreatedOn" DESC) AS "rn" + FROM public."ServerHistoryItem" shi + JOIN public."ServerItem" si ON shi."ServiceNowKey" = si."ServiceNowKey" + WHERE shi."InstallStatus" = 1 + AND shi."CreatedOn" >= last_month_start + AND ($3 IS NULL OR shi."CreatedOn" <= $3) + AND ($4 IS NULL OR shi."TenantId" = $4) + AND ($5 IS NULL OR shi."OrganizationId" = $5) + AND ($6 IS NULL OR shi."OperatingSystemItemId" = $6) + AND ($7 IS NULL OR shi."ServiceNowKey" = $7) + AND (si."TenantId" IN (SELECT "TenantId" FROM public."UserTenant" WHERE "UserId" = $1) + OR si."OrganizationId" IN (SELECT "OrganizationId" FROM public."UserOrganization" WHERE "UserId" = $1)) + ) AS "sub" + WHERE "rn" = 1 + ORDER BY "ServiceNowKey", "CreatedOn"; +END;$$ + +-- Use by calling +-- select * from public."FindServerHistoryItemsByMonthForUser"(1, '2023-12-01'); diff --git a/src/libs/dal/Migrations/20240801013229_1.0.4.Designer.cs b/src/libs/dal/Migrations/20240801013229_1.0.4.Designer.cs new file mode 100644 index 00000000..b2a4c9e0 --- /dev/null +++ b/src/libs/dal/Migrations/20240801013229_1.0.4.Designer.cs @@ -0,0 +1,1617 @@ +// +using System; +using System.Text.Json; +using HSB.DAL; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace HSB.DAL.Migrations +{ + [DbContext(typeof(HSBContext))] + [Migration("20240801013229_1.0.4")] + partial class _104 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("HSB.Entities.DataSync", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Offset") + .HasColumnType("integer"); + + b.Property("Query") + .IsRequired() + .HasColumnType("text"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "IsEnabled" }, "IX_DataSync"); + + b.HasIndex(new[] { "Name" }, "IX_DataSync_Name") + .IsUnique(); + + b.ToTable("DataSync", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.FileSystemHistoryItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AvailableSpace") + .HasColumnType("integer"); + + b.Property("Capacity") + .HasColumnType("integer"); + + b.Property("Category") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("ClassName") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("DiskSpace") + .HasColumnType("real"); + + b.Property("FreeSpace") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValueSql("''"); + + b.Property("FreeSpaceBytes") + .HasColumnType("bigint"); + + b.Property("InstallStatus") + .HasColumnType("integer"); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("MediaType") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("RawData") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("RawDataCI") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("ServerItemServiceNowKey") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ServiceNowKey") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Size") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValueSql("''"); + + b.Property("SizeBytes") + .HasColumnType("bigint"); + + b.Property("StorageType") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("Subcategory") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("UsedSizeBytes") + .HasColumnType("bigint"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.Property("VolumeId") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.HasKey("Id"); + + b.HasIndex("ServiceNowKey"); + + b.HasIndex(new[] { "CreatedOn" }, "IX_FileSystemHistoryItem_CreatedOn"); + + b.HasIndex(new[] { "InstallStatus", "ServiceNowKey", "ServerItemServiceNowKey" }, "IX_FileSystemHistoryItem_InstallStatus_ServiceNowKey_ServerItemServiceNowKey"); + + b.ToTable("FileSystemHistoryItem", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.FileSystemItem", b => + { + b.Property("ServiceNowKey") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("AvailableSpace") + .HasColumnType("integer"); + + b.Property("Capacity") + .HasColumnType("integer"); + + b.Property("Category") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("ClassName") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("DiskSpace") + .HasColumnType("real"); + + b.Property("FreeSpace") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValueSql("''"); + + b.Property("FreeSpaceBytes") + .HasColumnType("bigint"); + + b.Property("InstallStatus") + .HasColumnType("integer"); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("MediaType") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("RawData") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("RawDataCI") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("ServerItemServiceNowKey") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Size") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValueSql("''"); + + b.Property("SizeBytes") + .HasColumnType("bigint"); + + b.Property("StorageType") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("Subcategory") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("UsedSizeBytes") + .HasColumnType("bigint"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.Property("VolumeId") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.HasKey("ServiceNowKey"); + + b.HasIndex("ServerItemServiceNowKey"); + + b.HasIndex(new[] { "InstallStatus", "ServerItemServiceNowKey" }, "IX_FileSystemItem_InstallStatus_ServerItemServiceNowKey"); + + b.ToTable("FileSystemItem", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.Group", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("Key") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasDefaultValueSql("uuid_generate_v1()"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "IsEnabled" }, "IX_group"); + + b.HasIndex(new[] { "Key" }, "IX_group_key") + .IsUnique(); + + b.HasIndex(new[] { "Name" }, "IX_group_name") + .IsUnique(); + + b.ToTable("Group", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.GroupRole", b => + { + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("GroupId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("GroupRole", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.OperatingSystemItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("RawData") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("ServiceNowKey") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "Name" }, "IX_OperatingSystemItem_Name"); + + b.HasIndex(new[] { "ServiceNowKey" }, "IX_OperatingSystemItem_ServiceNowKey") + .IsUnique(); + + b.ToTable("OperatingSystemItem", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.Organization", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Code") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("ParentId") + .HasColumnType("integer"); + + b.Property("RawData") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("ServiceNowKey") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.HasIndex(new[] { "Code" }, "IX_Organization_Code") + .IsUnique(); + + b.HasIndex(new[] { "Name" }, "IX_Organization_Name") + .IsUnique(); + + b.HasIndex(new[] { "ServiceNowKey" }, "IX_Organization_ServiceNowKey") + .IsUnique(); + + b.ToTable("Organization", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("Key") + .ValueGeneratedOnAdd() + .HasColumnType("uuid") + .HasDefaultValueSql("uuid_generate_v1()"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "IsEnabled" }, "IX_role"); + + b.HasIndex(new[] { "Key" }, "IX_role_key") + .IsUnique(); + + b.HasIndex(new[] { "Name" }, "IX_role_name") + .IsUnique(); + + b.ToTable("Role", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.ServerHistoryItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AvailableSpace") + .HasColumnType("real"); + + b.Property("Capacity") + .HasColumnType("real"); + + b.Property("Category") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("ClassName") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("DiskSpace") + .HasColumnType("real"); + + b.Property("DnsDomain") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("FQDN") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("HistoryKey") + .HasColumnType("uuid"); + + b.Property("IPAddress") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValueSql("''"); + + b.Property("InstallStatus") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("OperatingSystemItemId") + .HasColumnType("integer"); + + b.Property("OrganizationId") + .HasColumnType("integer"); + + b.Property("Platform") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("RawData") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("RawDataCI") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("ServiceNowKey") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("Subcategory") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("TenantId") + .HasColumnType("integer"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("Id"); + + b.HasIndex("OperatingSystemItemId"); + + b.HasIndex("OrganizationId"); + + b.HasIndex("ServiceNowKey"); + + b.HasIndex("TenantId"); + + b.HasIndex(new[] { "CreatedOn" }, "IX_ServerHistoryItem_CreatedOn"); + + b.HasIndex(new[] { "HistoryKey" }, "IX_ServerHistoryItem_HistoryKey"); + + b.HasIndex(new[] { "InstallStatus", "ServiceNowKey" }, "IX_ServerHistoryItem_InstallStatus_ServiceNowKey"); + + b.ToTable("ServerHistoryItem", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.ServerItem", b => + { + b.Property("ServiceNowKey") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("AvailableSpace") + .HasColumnType("real"); + + b.Property("Capacity") + .HasColumnType("real"); + + b.Property("Category") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("ClassName") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("DiskSpace") + .HasColumnType("real"); + + b.Property("DnsDomain") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("FQDN") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("HistoryKey") + .HasColumnType("uuid"); + + b.Property("IPAddress") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValueSql("''"); + + b.Property("InstallStatus") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("OperatingSystemItemId") + .HasColumnType("integer"); + + b.Property("OrganizationId") + .HasColumnType("integer"); + + b.Property("Platform") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("RawData") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("RawDataCI") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("Subcategory") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(100) + .HasColumnType("character varying(100)") + .HasDefaultValueSql("''"); + + b.Property("TenantId") + .HasColumnType("integer"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("ServiceNowKey"); + + b.HasIndex("OperatingSystemItemId"); + + b.HasIndex("OrganizationId"); + + b.HasIndex("TenantId"); + + b.HasIndex(new[] { "InstallStatus", "UpdatedOn" }, "IX_ServerItem_InstallStatus_UpdatedOn"); + + b.ToTable("ServerItem", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.Tenant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Code") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("character varying(500)"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("RawData") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("ServiceNowKey") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("SortOrder") + .HasColumnType("integer"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("Id"); + + b.HasIndex(new[] { "Code" }, "IX_Tenant_Code") + .IsUnique(); + + b.HasIndex(new[] { "Name" }, "IX_Tenant_Name") + .IsUnique(); + + b.HasIndex(new[] { "ServiceNowKey" }, "IX_Tenant_ServiceNowKey") + .IsUnique(); + + b.ToTable("Tenant", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.TenantOrganization", b => + { + b.Property("TenantId") + .HasColumnType("integer"); + + b.Property("OrganizationId") + .HasColumnType("integer"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("TenantId", "OrganizationId"); + + b.HasIndex("OrganizationId"); + + b.ToTable("TenantOrganization", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("DisplayName") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValueSql("''"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("EmailVerified") + .HasColumnType("boolean"); + + b.Property("EmailVerifiedOn") + .HasColumnType("timestamp with time zone"); + + b.Property("FirstName") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValueSql("''"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("Key") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValueSql("uuid_generate_v1()"); + + b.Property("LastLoginOn") + .HasColumnType("timestamp with time zone"); + + b.Property("LastName") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValueSql("''"); + + b.Property("MiddleName") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(50) + .HasColumnType("character varying(50)") + .HasDefaultValueSql("''"); + + b.Property("Note") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValueSql("''"); + + b.Property("Phone") + .IsRequired() + .ValueGeneratedOnAdd() + .HasMaxLength(15) + .HasColumnType("character varying(15)") + .HasDefaultValueSql("''"); + + b.Property("Preferences") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("jsonb") + .HasDefaultValueSql("'{}'::jsonb"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("Id"); + + b.HasIndex("Email", "Phone", "LastName", "FirstName"); + + b.HasIndex(new[] { "DisplayName" }, "IX_user_display_name") + .IsUnique(); + + b.HasIndex(new[] { "Key" }, "IX_user_key") + .IsUnique(); + + b.HasIndex(new[] { "Username" }, "IX_user_username") + .IsUnique(); + + b.ToTable("User", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.UserGroup", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("GroupId") + .HasColumnType("integer"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("UserId", "GroupId"); + + b.HasIndex("GroupId"); + + b.ToTable("UserGroup", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.UserOrganization", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("OrganizationId") + .HasColumnType("integer"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("UserId", "OrganizationId"); + + b.HasIndex("OrganizationId"); + + b.ToTable("UserOrganization", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.UserTenant", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("TenantId") + .HasColumnType("integer"); + + b.Property("CreatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("CreatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("UpdatedBy") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("character varying(250)"); + + b.Property("UpdatedOn") + .ValueGeneratedOnAdd() + .HasColumnType("timestamp with time zone") + .HasDefaultValueSql("CURRENT_TIMESTAMP"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasDefaultValueSql("0"); + + b.HasKey("UserId", "TenantId"); + + b.HasIndex("TenantId"); + + b.ToTable("UserTenant", (string)null); + }); + + modelBuilder.Entity("HSB.Entities.FileSystemHistoryItem", b => + { + b.HasOne("HSB.Entities.FileSystemItem", "FileSystemItem") + .WithMany("History") + .HasForeignKey("ServiceNowKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("FileSystemItem"); + }); + + modelBuilder.Entity("HSB.Entities.FileSystemItem", b => + { + b.HasOne("HSB.Entities.ServerItem", "ServerItem") + .WithMany("FileSystemItems") + .HasForeignKey("ServerItemServiceNowKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ServerItem"); + }); + + modelBuilder.Entity("HSB.Entities.GroupRole", b => + { + b.HasOne("HSB.Entities.Group", "Group") + .WithMany("RolesManyToMany") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HSB.Entities.Role", "Role") + .WithMany("GroupsManyToMany") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("HSB.Entities.Organization", b => + { + b.HasOne("HSB.Entities.Organization", "Parent") + .WithMany("Children") + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("HSB.Entities.ServerHistoryItem", b => + { + b.HasOne("HSB.Entities.OperatingSystemItem", "OperatingSystemItem") + .WithMany() + .HasForeignKey("OperatingSystemItemId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("HSB.Entities.Organization", "Organization") + .WithMany() + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HSB.Entities.ServerItem", "ServerItem") + .WithMany("History") + .HasForeignKey("ServiceNowKey") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HSB.Entities.Tenant", "Tenant") + .WithMany() + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("OperatingSystemItem"); + + b.Navigation("Organization"); + + b.Navigation("ServerItem"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("HSB.Entities.ServerItem", b => + { + b.HasOne("HSB.Entities.OperatingSystemItem", "OperatingSystemItem") + .WithMany("ServerItems") + .HasForeignKey("OperatingSystemItemId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("HSB.Entities.Organization", "Organization") + .WithMany("ServerItems") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HSB.Entities.Tenant", "Tenant") + .WithMany("ServerItems") + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade); + + b.Navigation("OperatingSystemItem"); + + b.Navigation("Organization"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("HSB.Entities.TenantOrganization", b => + { + b.HasOne("HSB.Entities.Organization", "Organization") + .WithMany("TenantsManyToMany") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HSB.Entities.Tenant", "Tenant") + .WithMany("OrganizationsManyToMany") + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Organization"); + + b.Navigation("Tenant"); + }); + + modelBuilder.Entity("HSB.Entities.UserGroup", b => + { + b.HasOne("HSB.Entities.Group", "Group") + .WithMany("UsersManyToMany") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HSB.Entities.User", "User") + .WithMany("GroupsManyToMany") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HSB.Entities.UserOrganization", b => + { + b.HasOne("HSB.Entities.Organization", "Organization") + .WithMany("UsersManyToMany") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HSB.Entities.User", "User") + .WithMany("OrganizationsManyToMany") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Organization"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HSB.Entities.UserTenant", b => + { + b.HasOne("HSB.Entities.Tenant", "Tenant") + .WithMany("UsersManyToMany") + .HasForeignKey("TenantId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("HSB.Entities.User", "User") + .WithMany("TenantsManyToMany") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Tenant"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("HSB.Entities.FileSystemItem", b => + { + b.Navigation("History"); + }); + + modelBuilder.Entity("HSB.Entities.Group", b => + { + b.Navigation("RolesManyToMany"); + + b.Navigation("UsersManyToMany"); + }); + + modelBuilder.Entity("HSB.Entities.OperatingSystemItem", b => + { + b.Navigation("ServerItems"); + }); + + modelBuilder.Entity("HSB.Entities.Organization", b => + { + b.Navigation("Children"); + + b.Navigation("ServerItems"); + + b.Navigation("TenantsManyToMany"); + + b.Navigation("UsersManyToMany"); + }); + + modelBuilder.Entity("HSB.Entities.Role", b => + { + b.Navigation("GroupsManyToMany"); + }); + + modelBuilder.Entity("HSB.Entities.ServerItem", b => + { + b.Navigation("FileSystemItems"); + + b.Navigation("History"); + }); + + modelBuilder.Entity("HSB.Entities.Tenant", b => + { + b.Navigation("OrganizationsManyToMany"); + + b.Navigation("ServerItems"); + + b.Navigation("UsersManyToMany"); + }); + + modelBuilder.Entity("HSB.Entities.User", b => + { + b.Navigation("GroupsManyToMany"); + + b.Navigation("OrganizationsManyToMany"); + + b.Navigation("TenantsManyToMany"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/libs/dal/Migrations/20240801013229_1.0.4.cs b/src/libs/dal/Migrations/20240801013229_1.0.4.cs new file mode 100644 index 00000000..d54650b8 --- /dev/null +++ b/src/libs/dal/Migrations/20240801013229_1.0.4.cs @@ -0,0 +1,27 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using HSB.DAL; + +#nullable disable + +namespace HSB.DAL.Migrations +{ + /// + public partial class _104 : PostgresSeedMigration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + PreUp(migrationBuilder); + + PostUp(migrationBuilder); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + PreDown(migrationBuilder); + + PostDown(migrationBuilder); + } + } +} diff --git a/src/libs/dal/Migrations/HSBContextModelSnapshot.cs b/src/libs/dal/Migrations/HSBContextModelSnapshot.cs index 55020f18..08ce44a3 100644 --- a/src/libs/dal/Migrations/HSBContextModelSnapshot.cs +++ b/src/libs/dal/Migrations/HSBContextModelSnapshot.cs @@ -18,7 +18,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.14") + .HasAnnotation("ProductVersion", "8.0.6") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); diff --git a/src/libs/entities/FileSystemHistoryItem.cs b/src/libs/entities/FileSystemHistoryItem.cs index 35d41391..5145402c 100644 --- a/src/libs/entities/FileSystemHistoryItem.cs +++ b/src/libs/entities/FileSystemHistoryItem.cs @@ -1,108 +1,24 @@ using System.Text.Json; -using HSB.Core.Extensions; namespace HSB.Entities; -public class FileSystemHistoryItem : Auditable +public class FileSystemHistoryItem : FileSystemHistoryItemSmall { #region Properties - /// - /// get/set - Primary key (identity). - /// - public long Id { get; set; } - - /// - /// get/set - Foreign key to the file system this is a history of. - /// - public string ServiceNowKey { get; set; } = ""; - - /// - /// get/set - Foreign key to server that owns this file system item. - /// - public string ServerItemServiceNowKey { get; set; } = ""; - - /// - /// get/set - The file system this is a history of. - /// - public FileSystemItem? FileSystemItem { get; set; } - - #region ServiceNow Properties public JsonDocument RawData { get; set; } = JsonDocument.Parse("{}"); public JsonDocument RawDataCI { get; set; } = JsonDocument.Parse("{}"); - public string Name { get; set; } = ""; - public int InstallStatus { get; set; } - public string Label { get; set; } = ""; - public string Category { get; set; } = ""; - public string Subcategory { get; set; } = ""; - public string StorageType { get; set; } = ""; - public string MediaType { get; set; } = ""; - public string VolumeId { get; set; } = ""; - public string ClassName { get; set; } = ""; - public int Capacity { get; set; } - public float DiskSpace { get; set; } - public string Size { get; set; } = ""; - public long SizeBytes { get; set; } - public long? UsedSizeBytes { get; set; } - public int AvailableSpace { get; set; } - public string FreeSpace { get; set; } = ""; - public long FreeSpaceBytes { get; set; } - #endregion #endregion #region Constructors protected FileSystemHistoryItem() { } public FileSystemHistoryItem(string serverItemId, JsonDocument fileSystemItemData, JsonDocument configurationItemData) + : base(serverItemId, fileSystemItemData, configurationItemData) { - this.ServerItemServiceNowKey = serverItemId; - - this.RawData = fileSystemItemData; - this.RawDataCI = configurationItemData; - - this.ServiceNowKey = fileSystemItemData.GetElementValue(".sys_id") ?? ""; - this.ClassName = fileSystemItemData.GetElementValue(".sys_class_name") ?? ""; - this.Name = fileSystemItemData.GetElementValue(".name") ?? ""; - this.InstallStatus = fileSystemItemData.GetElementValue(".install_status"); - this.Label = fileSystemItemData.GetElementValue(".label") ?? ""; - this.Category = fileSystemItemData.GetElementValue(".category") ?? ""; - this.Subcategory = fileSystemItemData.GetElementValue(".subcategory") ?? ""; - this.StorageType = fileSystemItemData.GetElementValue(".u_platform") ?? ""; - this.MediaType = fileSystemItemData.GetElementValue(".dns_domain") ?? ""; - this.VolumeId = fileSystemItemData.GetElementValue(".volume_id") ?? ""; - this.Capacity = fileSystemItemData.GetElementValue(".capacity"); - this.DiskSpace = fileSystemItemData.GetElementValue(".disk_space"); - this.Size = fileSystemItemData.GetElementValue(".size") ?? ""; - this.SizeBytes = fileSystemItemData.GetElementValue(".size_bytes"); - this.UsedSizeBytes = fileSystemItemData.GetElementValue(".used_size_bytes"); - this.AvailableSpace = fileSystemItemData.GetElementValue(".available_space"); - this.FreeSpace = fileSystemItemData.GetElementValue(".free_space") ?? ""; - this.FreeSpaceBytes = fileSystemItemData.GetElementValue(".free_space_bytes"); } public FileSystemHistoryItem(FileSystemItem entity) + : base(entity) { - this.ServiceNowKey = entity.ServiceNowKey; - this.ServerItemServiceNowKey = entity.ServerItemServiceNowKey; - - this.RawData = entity.RawData; - this.RawDataCI = entity.RawDataCI; - - this.ClassName = entity.ClassName; - this.Name = entity.Name; - this.InstallStatus = entity.InstallStatus; - this.Label = entity.Label; - this.Category = entity.Category; - this.Subcategory = entity.Subcategory; - this.StorageType = entity.StorageType; - this.MediaType = entity.MediaType; - this.VolumeId = entity.VolumeId; - this.Capacity = entity.Capacity; - this.DiskSpace = entity.DiskSpace; - this.Size = entity.Size; - this.SizeBytes = entity.SizeBytes; - this.UsedSizeBytes = entity.UsedSizeBytes; - this.AvailableSpace = entity.AvailableSpace; - this.FreeSpace = entity.FreeSpace; - this.FreeSpaceBytes = entity.FreeSpaceBytes; } #endregion } diff --git a/src/libs/entities/FileSystemHistoryItemSmall.cs b/src/libs/entities/FileSystemHistoryItemSmall.cs new file mode 100644 index 00000000..34844991 --- /dev/null +++ b/src/libs/entities/FileSystemHistoryItemSmall.cs @@ -0,0 +1,101 @@ +using System.Text.Json; +using HSB.Core.Extensions; + +namespace HSB.Entities; +public class FileSystemHistoryItemSmall : Auditable +{ + #region Properties + /// + /// get/set - Primary key (identity). + /// + public long Id { get; set; } + + /// + /// get/set - Foreign key to the file system this is a history of. + /// + public string ServiceNowKey { get; set; } = ""; + + /// + /// get/set - Foreign key to server that owns this file system item. + /// + public string ServerItemServiceNowKey { get; set; } = ""; + + /// + /// get/set - The file system this is a history of. + /// + public FileSystemItem? FileSystemItem { get; set; } + + #region ServiceNow Properties + public string Name { get; set; } = ""; + public int InstallStatus { get; set; } + public string Label { get; set; } = ""; + public string Category { get; set; } = ""; + public string Subcategory { get; set; } = ""; + public string StorageType { get; set; } = ""; + public string MediaType { get; set; } = ""; + public string VolumeId { get; set; } = ""; + public string ClassName { get; set; } = ""; + public int Capacity { get; set; } + public float DiskSpace { get; set; } + public string Size { get; set; } = ""; + public long SizeBytes { get; set; } + public long? UsedSizeBytes { get; set; } + public int AvailableSpace { get; set; } + public string FreeSpace { get; set; } = ""; + public long FreeSpaceBytes { get; set; } + #endregion + #endregion + + #region Constructors + protected FileSystemHistoryItemSmall() { } + + public FileSystemHistoryItemSmall(string serverItemId, JsonDocument fileSystemItemData, JsonDocument configurationItemData) + { + this.ServerItemServiceNowKey = serverItemId; + + + this.ServiceNowKey = fileSystemItemData.GetElementValue(".sys_id") ?? ""; + this.ClassName = fileSystemItemData.GetElementValue(".sys_class_name") ?? ""; + this.Name = fileSystemItemData.GetElementValue(".name") ?? ""; + this.InstallStatus = fileSystemItemData.GetElementValue(".install_status"); + this.Label = fileSystemItemData.GetElementValue(".label") ?? ""; + this.Category = fileSystemItemData.GetElementValue(".category") ?? ""; + this.Subcategory = fileSystemItemData.GetElementValue(".subcategory") ?? ""; + this.StorageType = fileSystemItemData.GetElementValue(".u_platform") ?? ""; + this.MediaType = fileSystemItemData.GetElementValue(".dns_domain") ?? ""; + this.VolumeId = fileSystemItemData.GetElementValue(".volume_id") ?? ""; + this.Capacity = fileSystemItemData.GetElementValue(".capacity"); + this.DiskSpace = fileSystemItemData.GetElementValue(".disk_space"); + this.Size = fileSystemItemData.GetElementValue(".size") ?? ""; + this.SizeBytes = fileSystemItemData.GetElementValue(".size_bytes"); + this.UsedSizeBytes = fileSystemItemData.GetElementValue(".used_size_bytes"); + this.AvailableSpace = fileSystemItemData.GetElementValue(".available_space"); + this.FreeSpace = fileSystemItemData.GetElementValue(".free_space") ?? ""; + this.FreeSpaceBytes = fileSystemItemData.GetElementValue(".free_space_bytes"); + } + + public FileSystemHistoryItemSmall(FileSystemItem entity) + { + this.ServiceNowKey = entity.ServiceNowKey; + this.ServerItemServiceNowKey = entity.ServerItemServiceNowKey; + + this.ClassName = entity.ClassName; + this.Name = entity.Name; + this.InstallStatus = entity.InstallStatus; + this.Label = entity.Label; + this.Category = entity.Category; + this.Subcategory = entity.Subcategory; + this.StorageType = entity.StorageType; + this.MediaType = entity.MediaType; + this.VolumeId = entity.VolumeId; + this.Capacity = entity.Capacity; + this.DiskSpace = entity.DiskSpace; + this.Size = entity.Size; + this.SizeBytes = entity.SizeBytes; + this.UsedSizeBytes = entity.UsedSizeBytes; + this.AvailableSpace = entity.AvailableSpace; + this.FreeSpace = entity.FreeSpace; + this.FreeSpaceBytes = entity.FreeSpaceBytes; + } + #endregion +} diff --git a/src/libs/entities/ServerHistoryItem.cs b/src/libs/entities/ServerHistoryItem.cs index 8cbc8efa..a7cea641 100644 --- a/src/libs/entities/ServerHistoryItem.cs +++ b/src/libs/entities/ServerHistoryItem.cs @@ -1,107 +1,30 @@ using System.Text.Json; -using HSB.Core.Extensions; namespace HSB.Entities; -public class ServerHistoryItem : Auditable +public class ServerHistoryItem : ServerHistoryItemSmall { #region Properties - public long Id { get; set; } - public int? TenantId { get; set; } - public Tenant? Tenant { get; set; } - public int OrganizationId { get; set; } - public Organization? Organization { get; set; } - public int? OperatingSystemItemId { get; set; } - public OperatingSystemItem? OperatingSystemItem { get; set; } - - public string ServiceNowKey { get; set; } = ""; - public ServerItem? ServerItem { get; set; } - - /// - /// get/set - This key provides a way to map to the matching record in the history table. - /// This is required to update the calculated values. - /// - public Guid? HistoryKey { get; set; } - - #region ServiceNow Properties public JsonDocument RawData { get; set; } = JsonDocument.Parse("{}"); public JsonDocument RawDataCI { get; set; } = JsonDocument.Parse("{}"); - public string ClassName { get; set; } = ""; - public string Name { get; set; } = ""; - public int InstallStatus { get; set; } - public string Category { get; set; } = ""; - public string Subcategory { get; set; } = ""; - public string DnsDomain { get; set; } = ""; - public string Platform { get; set; } = ""; - public string IPAddress { get; set; } = ""; - public string FQDN { get; set; } = ""; - public float? DiskSpace { get; set; } - #endregion - - #region ServiceNow File System Item Summary Properties - public float? Capacity { get; set; } - public float? AvailableSpace { get; set; } - #endregion #endregion #region Constructors protected ServerHistoryItem() { } - public ServerHistoryItem(Tenant? tenant, Organization organization, OperatingSystemItem? operatingSystemItem, JsonDocument serverData, JsonDocument configurationData) - : this(tenant?.Id ?? 0, organization.Id, operatingSystemItem?.Id, serverData, configurationData) + public ServerHistoryItem(Tenant? tenant, Organization organization, OperatingSystemItem? operatingSystemItem, JsonDocument serverData, JsonDocument serverItemData) + : this(tenant?.Id ?? 0, organization.Id, operatingSystemItem?.Id, serverData, serverItemData) { - this.Tenant = tenant; - this.Tenant = tenant; - this.OperatingSystemItem = operatingSystemItem; } - public ServerHistoryItem(int? tenantId, int organizationId, int? operatingSystemItemId, JsonDocument serverData, JsonDocument configurationData) + public ServerHistoryItem(int? tenantId, int organizationId, int? operatingSystemItemId, JsonDocument serverData, JsonDocument serverItemData) + : base(tenantId, organizationId, operatingSystemItemId, serverData, serverItemData) { - this.TenantId = tenantId; - this.OrganizationId = organizationId; - this.OperatingSystemItemId = operatingSystemItemId; - - this.RawData = serverData; - this.RawDataCI = configurationData; - - this.ServiceNowKey = serverData.GetElementValue(".sys_id") ?? ""; - this.ClassName = serverData.GetElementValue(".sys_class_name") ?? ""; - this.Name = serverData.GetElementValue(".name") ?? ""; - this.InstallStatus = serverData.GetElementValue(".install_status"); - this.Category = serverData.GetElementValue(".category") ?? ""; - this.Subcategory = serverData.GetElementValue(".subcategory") ?? ""; - this.DnsDomain = serverData.GetElementValue(".dns_domain") ?? ""; - this.Platform = serverData.GetElementValue(".u_platform") ?? ""; - this.IPAddress = serverData.GetElementValue(".ip_address") ?? ""; - this.FQDN = serverData.GetElementValue(".fqdn") ?? ""; - this.DiskSpace = serverData.GetElementValue(".disk_space"); } public ServerHistoryItem(ServerItem entity) + : base(entity) { - this.ServiceNowKey = entity.ServiceNowKey; - this.HistoryKey = entity.HistoryKey; - - this.TenantId = entity.TenantId; - this.OrganizationId = entity.OrganizationId; - this.OperatingSystemItemId = entity.OperatingSystemItemId; - - this.RawData = entity.RawData; - this.RawDataCI = entity.RawDataCI; - - this.ClassName = entity.ClassName; - this.Name = entity.Name; - this.InstallStatus = entity.InstallStatus; - this.Category = entity.Category; - this.Subcategory = entity.Subcategory; - this.DnsDomain = entity.DnsDomain; - this.Platform = entity.Platform; - this.IPAddress = entity.IPAddress; - this.FQDN = entity.FQDN; - this.DiskSpace = entity.DiskSpace; - - this.Capacity = entity.Capacity; - this.AvailableSpace = entity.AvailableSpace; } #endregion } diff --git a/src/libs/entities/ServerHistoryItemSmall.cs b/src/libs/entities/ServerHistoryItemSmall.cs new file mode 100644 index 00000000..84573181 --- /dev/null +++ b/src/libs/entities/ServerHistoryItemSmall.cs @@ -0,0 +1,100 @@ +using System.Text.Json; +using HSB.Core.Extensions; + +namespace HSB.Entities; + +public class ServerHistoryItemSmall : Auditable +{ + #region Properties + public long Id { get; set; } + + public string ServiceNowKey { get; set; } = ""; + public int? TenantId { get; set; } + public Tenant? Tenant { get; set; } + public int OrganizationId { get; set; } + public Organization? Organization { get; set; } + public int? OperatingSystemItemId { get; set; } + public OperatingSystemItem? OperatingSystemItem { get; set; } + + public ServerItem? ServerItem { get; set; } + + /// + /// get/set - This key provides a way to map to the matching record in the history table. + /// This is required to update the calculated values. + /// + public Guid? HistoryKey { get; set; } + + #region ServiceNow Properties + public string ClassName { get; set; } = ""; + public string Name { get; set; } = ""; + public int InstallStatus { get; set; } + public string Category { get; set; } = ""; + public string Subcategory { get; set; } = ""; + public string DnsDomain { get; set; } = ""; + public string Platform { get; set; } = ""; + public string IPAddress { get; set; } = ""; + public string FQDN { get; set; } = ""; + public float? DiskSpace { get; set; } + #endregion + + #region ServiceNow File System Item Summary Properties + public float? Capacity { get; set; } + public float? AvailableSpace { get; set; } + #endregion + #endregion + + #region Constructors + protected ServerHistoryItemSmall() { } + + public ServerHistoryItemSmall(Tenant? tenant, Organization organization, OperatingSystemItem? operatingSystemItem, JsonDocument serverData, JsonDocument serverItemData) + : this(tenant?.Id ?? 0, organization.Id, operatingSystemItem?.Id, serverData, serverItemData) + { + this.Tenant = tenant; + this.Tenant = tenant; + this.OperatingSystemItem = operatingSystemItem; + } + + public ServerHistoryItemSmall(int? tenantId, int organizationId, int? operatingSystemItemId, JsonDocument serverData, JsonDocument serverItemData) + { + this.TenantId = tenantId; + this.OrganizationId = organizationId; + this.OperatingSystemItemId = operatingSystemItemId; + + this.ServiceNowKey = serverData.GetElementValue(".sys_id") ?? ""; + this.ClassName = serverData.GetElementValue(".sys_class_name") ?? ""; + this.Name = serverData.GetElementValue(".name") ?? ""; + this.InstallStatus = serverData.GetElementValue(".install_status"); + this.Category = serverData.GetElementValue(".category") ?? ""; + this.Subcategory = serverData.GetElementValue(".subcategory") ?? ""; + this.DnsDomain = serverData.GetElementValue(".dns_domain") ?? ""; + this.Platform = serverData.GetElementValue(".u_platform") ?? ""; + this.IPAddress = serverData.GetElementValue(".ip_address") ?? ""; + this.FQDN = serverData.GetElementValue(".fqdn") ?? ""; + this.DiskSpace = serverData.GetElementValue(".disk_space"); + } + + public ServerHistoryItemSmall(ServerItem entity) + { + this.ServiceNowKey = entity.ServiceNowKey; + this.HistoryKey = entity.HistoryKey; + + this.TenantId = entity.TenantId; + this.OrganizationId = entity.OrganizationId; + this.OperatingSystemItemId = entity.OperatingSystemItemId; + + this.ClassName = entity.ClassName; + this.Name = entity.Name; + this.InstallStatus = entity.InstallStatus; + this.Category = entity.Category; + this.Subcategory = entity.Subcategory; + this.DnsDomain = entity.DnsDomain; + this.Platform = entity.Platform; + this.IPAddress = entity.IPAddress; + this.FQDN = entity.FQDN; + this.DiskSpace = entity.DiskSpace; + + this.Capacity = entity.Capacity; + this.AvailableSpace = entity.AvailableSpace; + } + #endregion +} diff --git a/src/libs/keycloak/HSB.Keycloak.csproj b/src/libs/keycloak/HSB.Keycloak.csproj index bf6f55e8..ff345d8a 100644 --- a/src/libs/keycloak/HSB.Keycloak.csproj +++ b/src/libs/keycloak/HSB.Keycloak.csproj @@ -11,12 +11,12 @@ - + - + diff --git a/src/libs/models/FileSystemHistoryItemModel.cs b/src/libs/models/FileSystemHistoryItemModel.cs index ba242bed..7f6b520c 100644 --- a/src/libs/models/FileSystemHistoryItemModel.cs +++ b/src/libs/models/FileSystemHistoryItemModel.cs @@ -62,6 +62,31 @@ public FileSystemHistoryItemModel(FileSystemHistoryItem entity) : base(entity) this.FreeSpaceBytes = entity.FreeSpaceBytes; } + public FileSystemHistoryItemModel(FileSystemHistoryItemSmall entity) : base(entity) + { + this.Id = entity.Id; + + this.ServiceNowKey = entity.ServiceNowKey; + this.ServerItemServiceNowKey = entity.ServerItemServiceNowKey; + this.ClassName = entity.ClassName; + this.Name = entity.Name; + this.InstallStatus = entity.InstallStatus; + this.Label = entity.Label; + this.Category = entity.Category; + this.Subcategory = entity.Subcategory; + this.StorageType = entity.StorageType; + this.MediaType = entity.MediaType; + this.VolumeId = entity.VolumeId; + this.Capacity = entity.Capacity; + this.DiskSpace = entity.DiskSpace; + this.Size = entity.Size; + this.SizeBytes = entity.SizeBytes; + this.UsedSizeBytes = entity.UsedSizeBytes; + this.AvailableSpace = entity.AvailableSpace; + this.FreeSpace = entity.FreeSpace; + this.FreeSpaceBytes = entity.FreeSpaceBytes; + } + public FileSystemHistoryItemModel( string ServerItemServiceNowKey, ServiceNow.ResultModel fileSystemItemModel, diff --git a/src/libs/models/ServerHistoryItemModel.cs b/src/libs/models/ServerHistoryItemModel.cs index f9558654..1618b8b1 100644 --- a/src/libs/models/ServerHistoryItemModel.cs +++ b/src/libs/models/ServerHistoryItemModel.cs @@ -70,6 +70,30 @@ public ServerHistoryItemModel(ServerHistoryItem entity) : base(entity) this.AvailableSpace = entity.AvailableSpace; } + public ServerHistoryItemModel(ServerHistoryItemSmall entity) : base(entity) + { + this.Id = entity.Id; + + this.TenantId = entity.TenantId; + this.OrganizationId = entity.OrganizationId; + this.OperatingSystemItemId = entity.OperatingSystemItemId; + + this.ServiceNowKey = entity.ServiceNowKey; + this.ClassName = entity.ClassName; + this.Name = entity.Name; + this.InstallStatus = entity.InstallStatus; + this.Category = entity.Category; + this.Subcategory = entity.Subcategory; + this.DnsDomain = entity.DnsDomain; + this.Platform = entity.Platform; + this.IPAddress = entity.IPAddress; + this.FQDN = entity.FQDN; + this.DiskSpace = entity.DiskSpace; + + this.Capacity = entity.Capacity; + this.AvailableSpace = entity.AvailableSpace; + } + public ServerHistoryItemModel( int? tenantId, int organizationId,