-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add migration of device model commands from st table to database #1209 #1210
Merged
kbeaugrand
merged 1 commit into
main
from
feature/1209_migrate_device_model_commands_from_st_table_to_database
Sep 11, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
...IoTHub.Portal.Infrastructure/Migrations/20220911150200_Add DeviceModelCommand.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
src/AzureIoTHub.Portal.Infrastructure/Migrations/20220911150200_Add DeviceModelCommand.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,37 @@ | ||
// Copyright (c) CGI France. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
#nullable disable | ||
|
||
namespace AzureIoTHub.Portal.Infrastructure.Migrations | ||
{ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
public partial class AddDeviceModelCommand : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
_ = migrationBuilder.CreateTable( | ||
name: "DeviceModelCommands", | ||
columns: table => new | ||
{ | ||
Id = table.Column<string>(type: "text", nullable: false), | ||
Frame = table.Column<string>(type: "text", nullable: false), | ||
Confirmed = table.Column<bool>(type: "boolean", nullable: false), | ||
Port = table.Column<int>(type: "integer", nullable: false), | ||
IsBuiltin = table.Column<bool>(type: "boolean", nullable: false), | ||
DeviceModelId = table.Column<string>(type: "text", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
_ = table.PrimaryKey("PK_DeviceModelCommands", x => x.Id); | ||
}); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
_ = migrationBuilder.DropTable( | ||
name: "DeviceModelCommands"); | ||
} | ||
} | ||
} |
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
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
46 changes: 46 additions & 0 deletions
46
src/AzureIoTHub.Portal.Infrastructure/Seeds/DeviceModelCommandSeeder.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,46 @@ | ||
// 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 System.Globalization; | ||
using Azure.Data.Tables; | ||
using Domain; | ||
using Domain.Entities; | ||
using Factories; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
internal static class DeviceModelCommandSeeder | ||
{ | ||
public static async Task MigrateDeviceModelCommands(this PortalDbContext ctx, ConfigHandler config) | ||
{ | ||
var table = new TableClientFactory(config.StorageAccountConnectionString) | ||
.GetDeviceCommands(); | ||
|
||
var set = ctx.Set<DeviceModelCommand>(); | ||
|
||
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 DeviceModelCommand | ||
{ | ||
Id = item.RowKey, | ||
Frame = item[nameof(DeviceModelCommand.Frame)].ToString(), | ||
Port = int.Parse(item[nameof(DeviceModelCommand.Port)].ToString(), CultureInfo.InvariantCulture), | ||
IsBuiltin = bool.Parse(item[nameof(DeviceModelCommand.IsBuiltin)]?.ToString() ?? "false"), | ||
Confirmed = bool.Parse(item[nameof(DeviceModelCommand.Confirmed)]?.ToString() ?? "false"), | ||
DeviceModelId = item.PartitionKey | ||
}); | ||
#pragma warning restore CS8629 // Nullable value type may be null. | ||
|
||
if (config is ProductionConfigHandler) | ||
{ | ||
_ = await table.DeleteEntityAsync(item.PartitionKey, item.RowKey); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/AzureIoTHubPortal.Domain/Entities/DeviceModelCommand.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,23 @@ | ||
// 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.Domain.Entities | ||
{ | ||
using Base; | ||
using System.ComponentModel.DataAnnotations.Schema; | ||
|
||
public class DeviceModelCommand : EntityBase | ||
{ | ||
[NotMapped] public string Name => Id; | ||
|
||
public string Frame { get; set; } | ||
|
||
public bool Confirmed { get; set; } | ||
|
||
public int Port { get; set; } = 1; | ||
|
||
public bool IsBuiltin { get; set; } | ||
|
||
public string DeviceModelId { get; set; } | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Missed opportunity to use Where