feat: migrate runtime to postgresql

This commit is contained in:
2026-04-29 18:47:12 +08:00
parent 49d893f29b
commit 8132466c5d
17 changed files with 2347 additions and 306 deletions
@@ -848,21 +848,21 @@ public sealed partial class FfmpegService
var finalStatus = (int)recordTask.Status;
// Multiple background paths can reconcile the same segment after ffmpeg exits.
// Use SQLite's atomic upsert instead of EF Add-or-Update to avoid RecordTaskId
// unique constraint races between scoped DbContext instances.
// Use the database's atomic upsert instead of EF Add-or-Update to avoid
// RecordTaskId unique constraint races between scoped DbContext instances.
await dbContext.Database.ExecuteSqlInterpolatedAsync($"""
INSERT INTO RecordResults
(Id, RecordTaskId, FilePath, FileSizeBytes, DurationSeconds, DanmakuFilePath, DanmakuMessageCount, FinalStatus, ErrorMessage, CreatedAt)
INSERT INTO "RecordResults"
("Id", "RecordTaskId", "FilePath", "FileSizeBytes", "DurationSeconds", "DanmakuFilePath", "DanmakuMessageCount", "FinalStatus", "ErrorMessage", "CreatedAt")
VALUES
({resultId}, {recordTask.Id}, {effectiveOutputPath}, {fileSize}, {durationSeconds}, {danmakuFilePath}, {normalizedDanmakuCount}, {finalStatus}, {recordTask.ErrorMessage}, {endedAt})
ON CONFLICT(RecordTaskId) DO UPDATE SET
FilePath = excluded.FilePath,
FileSizeBytes = excluded.FileSizeBytes,
DurationSeconds = excluded.DurationSeconds,
DanmakuFilePath = excluded.DanmakuFilePath,
DanmakuMessageCount = excluded.DanmakuMessageCount,
FinalStatus = excluded.FinalStatus,
ErrorMessage = excluded.ErrorMessage;
ON CONFLICT("RecordTaskId") DO UPDATE SET
"FilePath" = excluded."FilePath",
"FileSizeBytes" = excluded."FileSizeBytes",
"DurationSeconds" = excluded."DurationSeconds",
"DanmakuFilePath" = excluded."DanmakuFilePath",
"DanmakuMessageCount" = excluded."DanmakuMessageCount",
"FinalStatus" = excluded."FinalStatus",
"ErrorMessage" = excluded."ErrorMessage";
""", cancellationToken);
}