Files
admin/Azaion.Common/Database/AzaionDbShemaHolder.cs
T
Oleksandr Bezdieniezhnykh 5ca9ccab2c [AZ-513] [AZ-196] [AZ-183] Add /classes CRUD, /devices, fleet OTA
AZ-513: POST/PATCH/DELETE /classes for detection-class CRUD; new
DetectionClass entity, schema, DTOs, IDetectionClassService. Unblocks
ui/AZ-512.

AZ-196: POST /devices auto-assigns sequential azj-NNNN serial+email
+password and inserts a CompanionPC user. Returns plaintext credentials
for the provisioning script.

AZ-183: Resources table + POST /get-update + POST /resources/publish
for fleet OTA. Per-resource encryption_key column AES-256-CBC encrypted
at rest with ResourcesConfig.EncryptionMasterKey; ICache wraps the
per-(arch,stage) latest-versions lookup and is invalidated on publish.

Adds IDbFactory.RunAdmin<T> overload for write-and-return.

Backfills _docs/02_document/module-layout.md to satisfy the implement
skill's File Ownership prerequisite (the _docs/ artifact set predates
the Step 1.5 module-layout addition).

Code review: PASS_WITH_WARNINGS — see
_docs/03_implementation/reviews/batch_05_review.md.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 04:34:42 +03:00

53 lines
1.7 KiB
C#

using Azaion.Common.Entities;
using Azaion.Common.Extensions;
using LinqToDB;
using LinqToDB.Mapping;
using Newtonsoft.Json;
namespace Azaion.Common.Database;
public static class AzaionDbSchemaHolder
{
public static readonly MappingSchema MappingSchema;
static AzaionDbSchemaHolder()
{
MappingSchema = new MappingSchema();
MappingSchema.EntityDescriptorCreatedCallback = (_, entityDescriptor) =>
{
foreach (var entityDescriptorColumn in entityDescriptor.Columns)
entityDescriptorColumn.ColumnName = entityDescriptorColumn.ColumnName.ToSnakeCase();
};
var builder = new FluentMappingBuilder(MappingSchema);
builder.Entity<User>()
.HasTableName("users")
.Property(x => x.Id)
.IsPrimaryKey()
.HasDataType(DataType.Guid)
.Property(x => x.Role)
.HasDataType(DataType.Text)
.HasConversion(v => v.ToString(), v => (RoleEnum)Enum.Parse(typeof(RoleEnum), v))
.Property(x => x.UserConfig)
.HasConversion(
v => v == null ? null : JsonConvert.SerializeObject(v),
p => string.IsNullOrEmpty(p) ? new UserConfig() : JsonConvert.DeserializeObject<UserConfig>(p))
.IsNullable();
builder.Entity<DetectionClass>()
.HasTableName("detection_classes")
.Property(x => x.Id)
.IsPrimaryKey()
.IsIdentity();
builder.Entity<Resource>()
.HasTableName("resources")
.Property(x => x.Id)
.IsPrimaryKey()
.HasDataType(DataType.Guid);
builder.Build();
}
}