thecr3w-dev/backend/TheCr3w.Shared/Data/Entities.cs

389 lines
10 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace TheCr3w.Shared.Data;
[Table("applications")]
public class ApplicationEntity
{
[Key]
[Column("app_id")]
[MaxLength(128)]
public string AppId { get; set; } = string.Empty;
[Column("name")]
[MaxLength(255)]
public string Name { get; set; } = string.Empty;
[Column("description")]
public string? Description { get; set; }
[Column("icon_url")]
public string? IconUrl { get; set; }
[Column("is_public")]
public bool IsPublic { get; set; } = true;
[Column("default_channel")]
[MaxLength(32)]
public string DefaultChannel { get; set; } = "stable";
[Column("system_requirements")]
public string? SystemRequirements { get; set; }
[Column("created_at")]
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
[Column("updated_at")]
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
public List<ApplicationPlatformEntity> Platforms { get; set; } = new();
public List<ReleaseEntity> Releases { get; set; } = new();
}
[Table("application_platforms")]
public class ApplicationPlatformEntity
{
[Column("app_id")]
[MaxLength(128)]
public string AppId { get; set; } = string.Empty;
[Column("platform")]
[MaxLength(32)]
public string Platform { get; set; } = string.Empty;
[Column("package_identifier")]
[MaxLength(255)]
public string PackageIdentifier { get; set; } = string.Empty;
[Column("signing_certificate_fingerprint")]
[MaxLength(128)]
public string? SigningCertificateFingerprint { get; set; }
public ApplicationEntity? Application { get; set; }
}
[Table("releases")]
public class ReleaseEntity
{
[Key]
[Column("release_id")]
public Guid ReleaseId { get; set; } = Guid.NewGuid();
[Column("app_id")]
[MaxLength(128)]
public string AppId { get; set; } = string.Empty;
[Column("version")]
[MaxLength(64)]
public string Version { get; set; } = string.Empty;
[Column("version_code")]
public int VersionCode { get; set; }
[Column("platform")]
[MaxLength(32)]
public string Platform { get; set; } = string.Empty;
[Column("architecture")]
[MaxLength(32)]
public string Architecture { get; set; } = string.Empty;
[Column("channel")]
[MaxLength(32)]
public string Channel { get; set; } = string.Empty;
[Column("status")]
[MaxLength(32)]
public string Status { get; set; } = "draft"; // draft, published, revoked
[Column("mandatory")]
public bool Mandatory { get; set; }
[Column("minimum_supported_version")]
[MaxLength(64)]
public string? MinimumSupportedVersion { get; set; }
[Column("release_notes")]
public string? ReleaseNotes { get; set; }
[Column("file_size_bytes")]
public long FileSizeBytes { get; set; }
[Column("sha256")]
[MaxLength(64)]
public string Sha256 { get; set; } = string.Empty;
[Column("r2_object_key")]
[MaxLength(512)]
public string R2ObjectKey { get; set; } = string.Empty;
[Column("signature_ed25519")]
[MaxLength(128)]
public string? SignatureEd25519 { get; set; }
[Column("signing_key_id")]
[MaxLength(64)]
public string? SigningKeyId { get; set; }
[Column("published_at")]
public DateTimeOffset? PublishedAt { get; set; }
[Column("revoked_at")]
public DateTimeOffset? RevokedAt { get; set; }
[Column("revocation_reason")]
public string? RevocationReason { get; set; }
[Column("created_at")]
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
[Column("created_by")]
[MaxLength(255)]
public string CreatedBy { get; set; } = string.Empty;
public ApplicationEntity? Application { get; set; }
}
[Table("installation_reports")]
public class InstallationReportEntity
{
[Key]
[Column("report_id")]
public Guid ReportId { get; set; } = Guid.NewGuid();
[Column("release_id")]
public Guid ReleaseId { get; set; }
[Column("previous_version")]
[MaxLength(64)]
public string? PreviousVersion { get; set; }
[Column("installed_version")]
[MaxLength(64)]
public string InstalledVersion { get; set; } = string.Empty;
[Column("status")]
[MaxLength(32)]
public string Status { get; set; } = "success"; // success, failed, rolled_back
[Column("duration_seconds")]
public int? DurationSeconds { get; set; }
[Column("os_version")]
[MaxLength(64)]
public string? OsVersion { get; set; }
[Column("device_model")]
[MaxLength(128)]
public string? DeviceModel { get; set; }
[Column("error_details")]
public string? ErrorDetails { get; set; }
[Column("reported_at")]
public DateTimeOffset ReportedAt { get; set; } = DateTimeOffset.UtcNow;
}
[Table("error_reports")]
public class ErrorReportEntity
{
[Key]
[Column("error_id")]
public Guid ErrorId { get; set; } = Guid.NewGuid();
[Column("release_id")]
public Guid? ReleaseId { get; set; }
[Column("app_id")]
[MaxLength(128)]
public string AppId { get; set; } = string.Empty;
[Column("error_code")]
[MaxLength(64)]
public string ErrorCode { get; set; } = string.Empty;
[Column("error_message")]
public string ErrorMessage { get; set; } = string.Empty;
[Column("stack_trace")]
public string? StackTrace { get; set; }
[Column("client_platform")]
[MaxLength(32)]
public string? ClientPlatform { get; set; }
[Column("reported_at")]
public DateTimeOffset ReportedAt { get; set; } = DateTimeOffset.UtcNow;
}
[Table("deployment_manifests")]
public class DeploymentManifestEntity
{
[Key]
[Column("manifest_id")]
public Guid ManifestId { get; set; } = Guid.NewGuid();
[Column("project_id")]
[MaxLength(64)]
public string ProjectId { get; set; } = string.Empty;
[Column("environment_id")]
[MaxLength(32)]
public string EnvironmentId { get; set; } = "production";
[Column("service_name")]
[MaxLength(128)]
public string ServiceName { get; set; } = string.Empty;
[Column("image")]
[MaxLength(255)]
public string Image { get; set; } = string.Empty;
[Column("immutable_digest")]
[MaxLength(128)]
public string ImmutableDigest { get; set; } = string.Empty;
[Column("manifest_sha256")]
[MaxLength(64)]
public string ManifestSha256 { get; set; } = string.Empty;
[Column("signature_ed25519")]
[MaxLength(128)]
public string SignatureEd25519 { get; set; } = string.Empty;
[Column("config_hash")]
[MaxLength(64)]
public string ConfigHash { get; set; } = string.Empty;
[Column("status")]
[MaxLength(32)]
public string Status { get; set; } = "pending"; // pending, approved, rejected, in_progress, completed, failed, rolled_back
[Column("created_at")]
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
[Column("created_by")]
[MaxLength(255)]
public string CreatedBy { get; set; } = string.Empty;
}
[Table("deployment_approvals")]
public class DeploymentApprovalEntity
{
[Key]
[Column("approval_id")]
public Guid ApprovalId { get; set; } = Guid.NewGuid();
[Column("manifest_id")]
public Guid ManifestId { get; set; }
[Column("manifest_sha256_verified")]
[MaxLength(64)]
public string ManifestSha256Verified { get; set; } = string.Empty;
[Column("approver")]
[MaxLength(255)]
public string Approver { get; set; } = string.Empty;
[Column("decision")]
[MaxLength(32)]
public string Decision { get; set; } = "approved";
[Column("comment")]
public string? Comment { get; set; }
[Column("decided_at")]
public DateTimeOffset DecidedAt { get; set; } = DateTimeOffset.UtcNow;
}
[Table("audit_events")]
public class AuditEventEntity
{
[Key]
[Column("event_id")]
public Guid EventId { get; set; } = Guid.NewGuid();
[Column("actor")]
[MaxLength(255)]
public string Actor { get; set; } = string.Empty;
[Column("action")]
[MaxLength(128)]
public string Action { get; set; } = string.Empty;
[Column("resource_type")]
[MaxLength(128)]
public string ResourceType { get; set; } = string.Empty;
[Column("resource_id")]
[MaxLength(255)]
public string ResourceId { get; set; } = string.Empty;
[Column("correlation_id")]
public Guid CorrelationId { get; set; } = Guid.NewGuid();
[Column("ip_address")]
[MaxLength(64)]
public string? IpAddress { get; set; }
[Column("user_agent")]
public string? UserAgent { get; set; }
[Column("success")]
public bool Success { get; set; } = true;
[Column("error_message")]
public string? ErrorMessage { get; set; }
[Column("details_json")]
public string? DetailsJson { get; set; }
[Column("created_at")]
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
}
[Table("external_servers")]
public class ExternalServerEntity
{
[Key]
[Column("server_id")]
public Guid ServerId { get; set; } = Guid.NewGuid();
[Column("name")]
[MaxLength(255)]
public string Name { get; set; } = string.Empty;
[Column("protocol")]
[MaxLength(16)]
public string Protocol { get; set; } = "sftp"; // sftp, ftps, ftp
[Column("host")]
[MaxLength(255)]
public string Host { get; set; } = string.Empty;
[Column("port")]
public int Port { get; set; } = 22;
[Column("remote_root_path")]
[MaxLength(512)]
public string RemoteRootPath { get; set; } = "/";
[Column("host_key_fingerprint")]
[MaxLength(255)]
public string? HostKeyFingerprint { get; set; }
[Column("tls_certificate_thumbprint")]
[MaxLength(128)]
public string? TlsCertificateThumbprint { get; set; }
[Column("status")]
[MaxLength(32)]
public string Status { get; set; } = "active";
[Column("created_at")]
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
[Column("updated_at")]
public DateTimeOffset UpdatedAt { get; set; } = DateTimeOffset.UtcNow;
}