-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error logging when exception occures during database seeding (#1197)
* Add error logging when exception occures during database seeding * Fix #1190 - Add seeding during Startup manually
- Loading branch information
1 parent
0c0dfaf
commit b573f21
Showing
4 changed files
with
63 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/AzureIoTHub.Portal.Infrastructure/Seeds/DeviceModelPropertySeeder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) CGI France. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace AzureIoTHub.Portal.Infrastructure.Seeds | ||
{ | ||
using Azure.Data.Tables; | ||
using AzureIoTHub.Portal.Domain; | ||
using AzureIoTHub.Portal.Domain.Entities; | ||
using AzureIoTHub.Portal.Models; | ||
using AzureIoTHub.Portal.Infrastructure.Factories; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
internal static class DeviceModelPropertySeeder | ||
{ | ||
public static async Task MigrateDeviceModelProperties(this PortalDbContext ctx, ConfigHandler config) | ||
{ | ||
var table = new TableClientFactory(config.StorageAccountConnectionString) | ||
.GetDeviceTemplateProperties(); | ||
|
||
var set = ctx.Set<DeviceModelProperty>(); | ||
|
||
foreach (var item in table.Query<TableEntity>().ToArray()) | ||
{ | ||
if (await set.AnyAsync(c => c.Id == item.RowKey)) | ||
continue; | ||
|
||
#pragma warning disable CS8629 // Nullable value type may be null. | ||
_ = await set.AddAsync(new DeviceModelProperty | ||
{ | ||
Id = item.RowKey, | ||
ModelId = item.PartitionKey, | ||
Name = item.GetString(nameof(DeviceModelProperty.Name)), | ||
DisplayName = item.GetString(nameof(DeviceModelProperty.DisplayName)), | ||
PropertyType = Enum.Parse<DevicePropertyType>(item.GetString(nameof(DeviceModelProperty.PropertyType))), | ||
Order = item.GetInt32(nameof(DeviceModelProperty.Order)) ?? 0, | ||
IsWritable = item.GetBoolean(nameof(DeviceModelProperty.IsWritable)).Value | ||
}); | ||
#pragma warning restore CS8629 // Nullable value type may be null. | ||
|
||
if (config is ProductionConfigHandler) | ||
{ | ||
_ = await table.DeleteEntityAsync(item.PartitionKey, item.RowKey); | ||
} | ||
} | ||
} | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
src/AzureIoTHub.Portal.Infrastructure/Seeds/DeviceModelPropoertySeeder.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters