Files
DatabaseSnapshots/Models/DataModels.cs
GuilhermeStrice 1108bf3ef6 add project
2025-07-09 19:24:12 +01:00

242 lines
7.0 KiB
C#

using System.Text.Json.Serialization;
namespace DatabaseSnapshotsService.Models
{
public class SnapshotInfo
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("type")]
public string Type { get; set; } = string.Empty;
[JsonPropertyName("timestamp")]
public long Timestamp { get; set; }
[JsonPropertyName("dataSize")]
public long DataSize { get; set; }
[JsonPropertyName("status")]
public string Status { get; set; } = string.Empty;
[JsonPropertyName("description")]
public string? Description { get; set; }
[JsonPropertyName("userId")]
public int? UserId { get; set; }
[JsonPropertyName("createdAt")]
public DateTime CreatedAt { get; set; }
[JsonPropertyName("filePath")]
public string FilePath { get; set; } = string.Empty;
[JsonPropertyName("checksum")]
public string Checksum { get; set; } = string.Empty;
// Binlog fields for incremental snapshots
[JsonPropertyName("binlogFile")]
public string? BinlogFile { get; set; }
[JsonPropertyName("binlogPosition")]
public long? BinlogPosition { get; set; }
[JsonPropertyName("parentSnapshotId")]
public int? ParentSnapshotId { get; set; }
[JsonPropertyName("incrementalBinlogStartFile")]
public string? IncrementalBinlogStartFile { get; set; }
[JsonPropertyName("incrementalBinlogStartPosition")]
public long? IncrementalBinlogStartPosition { get; set; }
[JsonPropertyName("incrementalBinlogEndFile")]
public string? IncrementalBinlogEndFile { get; set; }
[JsonPropertyName("incrementalBinlogEndPosition")]
public long? IncrementalBinlogEndPosition { get; set; }
}
public class DatabaseEvent
{
[JsonPropertyName("id")]
public long Id { get; set; }
[JsonPropertyName("timestamp")]
public long Timestamp { get; set; }
[JsonPropertyName("type")]
public string Type { get; set; } = string.Empty;
[JsonPropertyName("table")]
public string Table { get; set; } = string.Empty;
[JsonPropertyName("operation")]
public string Operation { get; set; } = string.Empty;
[JsonPropertyName("data")]
public string Data { get; set; } = string.Empty;
[JsonPropertyName("binlogPosition")]
public long BinlogPosition { get; set; }
[JsonPropertyName("serverId")]
public int ServerId { get; set; }
[JsonPropertyName("checksum")]
public string Checksum { get; set; } = string.Empty;
}
public class RecoveryPoint
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("timestamp")]
public long Timestamp { get; set; }
[JsonPropertyName("description")]
public string? Description { get; set; }
[JsonPropertyName("eventCount")]
public long EventCount { get; set; }
[JsonPropertyName("createdAt")]
public DateTime CreatedAt { get; set; }
[JsonPropertyName("lastEventId")]
public long LastEventId { get; set; }
}
public class ServiceStatus
{
[JsonPropertyName("status")]
public string Status { get; set; } = "Unknown";
[JsonPropertyName("databaseConnected")]
public bool DatabaseConnected { get; set; }
[JsonPropertyName("binlogReaderStatus")]
public string BinlogReaderStatus { get; set; } = "Unknown";
[JsonPropertyName("lastEventProcessed")]
public long LastEventProcessed { get; set; }
[JsonPropertyName("totalEvents")]
public long TotalEvents { get; set; }
[JsonPropertyName("activeSnapshots")]
public int ActiveSnapshots { get; set; }
[JsonPropertyName("uptime")]
public TimeSpan Uptime { get; set; }
[JsonPropertyName("lastSnapshot")]
public DateTime? LastSnapshot { get; set; }
}
public class HealthStatus
{
[JsonPropertyName("isHealthy")]
public bool IsHealthy { get; set; }
[JsonPropertyName("errorMessage")]
public string? ErrorMessage { get; set; }
[JsonPropertyName("checks")]
public Dictionary<string, bool> Checks { get; set; } = new();
[JsonPropertyName("timestamp")]
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}
public class RestorePreview
{
[JsonPropertyName("targetTimestamp")]
public long TargetTimestamp { get; set; }
[JsonPropertyName("eventCount")]
public long EventCount { get; set; }
[JsonPropertyName("affectedTables")]
public List<string> AffectedTables { get; set; } = new();
[JsonPropertyName("estimatedDuration")]
public TimeSpan EstimatedDuration { get; set; }
[JsonPropertyName("snapshotId")]
public int? SnapshotId { get; set; }
[JsonPropertyName("warnings")]
public List<string> Warnings { get; set; } = new();
}
public class SnapshotMetadata
{
[JsonPropertyName("version")]
public string Version { get; set; } = "1.0";
[JsonPropertyName("createdAt")]
public DateTime CreatedAt { get; set; }
[JsonPropertyName("databaseVersion")]
public string DatabaseVersion { get; set; } = string.Empty;
[JsonPropertyName("tables")]
public List<TableInfo> Tables { get; set; } = new();
[JsonPropertyName("checksum")]
public string Checksum { get; set; } = string.Empty;
[JsonPropertyName("compression")]
public bool Compression { get; set; }
[JsonPropertyName("encryption")]
public bool Encryption { get; set; }
}
public class TableInfo
{
[JsonPropertyName("name")]
public string Name { get; set; } = string.Empty;
[JsonPropertyName("rowCount")]
public long RowCount { get; set; }
[JsonPropertyName("dataSize")]
public long DataSize { get; set; }
[JsonPropertyName("indexSize")]
public long IndexSize { get; set; }
[JsonPropertyName("checksum")]
public string Checksum { get; set; } = string.Empty;
}
public enum SnapshotType
{
Full,
Trading,
User,
Incremental
}
public enum EventOperation
{
Insert,
Update,
Delete,
Truncate
}
public enum SnapshotStatus
{
Creating,
Completed,
Failed,
Corrupted
}
}