Bundle from worker to grain

This commit is contained in:
2025-09-15 12:56:59 +07:00
parent 77e6ce0789
commit 63bc7bbe59
19 changed files with 2112 additions and 79 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,61 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Managing.Infrastructure.Databases.Migrations
{
/// <inheritdoc />
public partial class ChangeRequestIdToGuid : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
// Convert BundleBacktestRequests.RequestId from varchar to uuid
// First, ensure all values are valid UUIDs or convert them
migrationBuilder.Sql(@"
UPDATE ""BundleBacktestRequests""
SET ""RequestId"" = gen_random_uuid()::text
WHERE ""RequestId"" IS NULL OR ""RequestId"" = '' OR
""RequestId"" !~ '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$';
");
// Now convert the column type using the USING clause
migrationBuilder.Sql(@"
ALTER TABLE ""BundleBacktestRequests""
ALTER COLUMN ""RequestId"" TYPE uuid USING ""RequestId""::uuid;
");
// Convert Backtests.RequestId from varchar to uuid
// First, ensure all values are valid UUIDs or convert them
migrationBuilder.Sql(@"
UPDATE ""Backtests""
SET ""RequestId"" = gen_random_uuid()::text
WHERE ""RequestId"" IS NULL OR ""RequestId"" = '' OR
""RequestId"" !~ '^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$';
");
// Now convert the column type using the USING clause
migrationBuilder.Sql(@"
ALTER TABLE ""Backtests""
ALTER COLUMN ""RequestId"" TYPE uuid USING ""RequestId""::uuid;
");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
// Convert BundleBacktestRequests.RequestId from uuid back to varchar
migrationBuilder.Sql(@"
ALTER TABLE ""BundleBacktestRequests""
ALTER COLUMN ""RequestId"" TYPE character varying(255) USING ""RequestId""::text;
");
// Convert Backtests.RequestId from uuid back to varchar
migrationBuilder.Sql(@"
ALTER TABLE ""Backtests""
ALTER COLUMN ""RequestId"" TYPE character varying(255) USING ""RequestId""::text;
");
}
}
}

View File

@@ -176,10 +176,9 @@ namespace Managing.Infrastructure.Databases.Migrations
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("RequestId")
.IsRequired()
b.Property<Guid>("RequestId")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
.HasColumnType("uuid");
b.Property<double>("Score")
.HasColumnType("double precision");
@@ -339,10 +338,9 @@ namespace Managing.Infrastructure.Databases.Migrations
b.Property<string>("ProgressInfo")
.HasColumnType("text");
b.Property<string>("RequestId")
.IsRequired()
b.Property<Guid>("RequestId")
.HasMaxLength(255)
.HasColumnType("character varying(255)");
.HasColumnType("uuid");
b.Property<string>("ResultsJson")
.IsRequired()

View File

@@ -15,8 +15,7 @@ public class BacktestEntity
public string Identifier { get; set; } = string.Empty;
[Required]
[MaxLength(255)]
public string RequestId { get; set; } = string.Empty;
public Guid RequestId { get; set; }
[Required]
[Column(TypeName = "decimal(18,8)")]

View File

@@ -12,8 +12,7 @@ public class BundleBacktestRequestEntity
public int Id { get; set; }
[Required]
[MaxLength(255)]
public string RequestId { get; set; } = string.Empty;
public Guid RequestId { get; set; }
// Foreign key to User entity
public int? UserId { get; set; }

View File

@@ -91,7 +91,7 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
return entities.Select(PostgreSqlMappers.Map);
}
public IEnumerable<Backtest> GetBacktestsByRequestId(string requestId)
public IEnumerable<Backtest> GetBacktestsByRequestId(Guid requestId)
{
var entities = _context.Backtests
.AsNoTracking()
@@ -101,7 +101,7 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
return entities.Select(PostgreSqlMappers.Map);
}
public async Task<IEnumerable<Backtest>> GetBacktestsByRequestIdAsync(string requestId)
public async Task<IEnumerable<Backtest>> GetBacktestsByRequestIdAsync(Guid requestId)
{
var entities = await _context.Backtests
.AsNoTracking()
@@ -112,7 +112,7 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
return entities.Select(PostgreSqlMappers.Map);
}
public (IEnumerable<LightBacktest> Backtests, int TotalCount) GetBacktestsByRequestIdPaginated(string requestId,
public (IEnumerable<LightBacktest> Backtests, int TotalCount) GetBacktestsByRequestIdPaginated(Guid requestId,
int page, int pageSize, string sortBy = "score", string sortOrder = "desc")
{
var stopwatch = Stopwatch.StartNew();
@@ -185,7 +185,7 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
}
public async Task<(IEnumerable<LightBacktest> Backtests, int TotalCount)> GetBacktestsByRequestIdPaginatedAsync(
string requestId, int page, int pageSize, string sortBy = "score", string sortOrder = "desc")
Guid requestId, int page, int pageSize, string sortBy = "score", string sortOrder = "desc")
{
var stopwatch = Stopwatch.StartNew();
@@ -348,7 +348,7 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
}
}
public void DeleteBacktestsByRequestId(string requestId)
public void DeleteBacktestsByRequestId(Guid requestId)
{
var entities = _context.Backtests
.AsTracking()
@@ -362,7 +362,7 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
}
}
public async Task DeleteBacktestsByRequestIdAsync(string requestId)
public async Task DeleteBacktestsByRequestIdAsync(Guid requestId)
{
var entities = await _context.Backtests
.AsTracking()
@@ -580,7 +580,7 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
return entities.Select(PostgreSqlMappers.Map);
}
public BundleBacktestRequest? GetBundleBacktestRequestByIdForUser(User user, string id)
public BundleBacktestRequest? GetBundleBacktestRequestByIdForUser(User user, Guid id)
{
var entity = _context.BundleBacktestRequests
.AsNoTracking()
@@ -590,7 +590,7 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
return entity != null ? PostgreSqlMappers.Map(entity) : null;
}
public async Task<BundleBacktestRequest?> GetBundleBacktestRequestByIdForUserAsync(User user, string id)
public async Task<BundleBacktestRequest?> GetBundleBacktestRequestByIdForUserAsync(User user, Guid id)
{
var entity = await _context.BundleBacktestRequests
.AsNoTracking()
@@ -682,7 +682,7 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
}
}
public void DeleteBundleBacktestRequestByIdForUser(User user, string id)
public void DeleteBundleBacktestRequestByIdForUser(User user, Guid id)
{
var entity = _context.BundleBacktestRequests
.AsTracking()
@@ -695,7 +695,7 @@ public class PostgreSqlBacktestRepository : IBacktestRepository
}
}
public async Task DeleteBundleBacktestRequestByIdForUserAsync(User user, string id)
public async Task DeleteBundleBacktestRequestByIdForUserAsync(User user, Guid id)
{
var entity = await _context.BundleBacktestRequests
.AsTracking()