forked from gongxuegit/tiku-backend.net
feat: add commerce refunds and reconciliation persistence
This commit is contained in:
@@ -55,6 +55,7 @@ public sealed class Order : AuditableTenantEntity
|
||||
public string? PayProvider { get; set; }
|
||||
public string? TradeNo { get; set; }
|
||||
public int? Days { get; set; }
|
||||
public int RefundedAmountCents { get; set; }
|
||||
public DateTimeOffset? PaidAt { get; set; }
|
||||
public JsonElement RawPayload { get; set; } = JsonDefaults.Object();
|
||||
}
|
||||
@@ -81,6 +82,7 @@ public sealed class Payment : AuditableTenantEntity
|
||||
public string? Method { get; set; }
|
||||
public PaymentStatus Status { get; set; } = PaymentStatus.Pending;
|
||||
public int AmountCents { get; set; }
|
||||
public int RefundedAmountCents { get; set; }
|
||||
public string? ProviderTradeNo { get; set; }
|
||||
public DateTimeOffset? PaidAt { get; set; }
|
||||
public JsonElement RawPayload { get; set; } = JsonDefaults.Object();
|
||||
@@ -113,6 +115,9 @@ public sealed class Entitlement : Entity
|
||||
public DateTimeOffset StartsAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTimeOffset? ExpiresAt { get; set; }
|
||||
public EntitlementStatus Status { get; set; } = EntitlementStatus.Active;
|
||||
public DateTimeOffset? RevokedAt { get; set; }
|
||||
public Guid? RevokedBy { get; set; }
|
||||
public string? RevokedReason { get; set; }
|
||||
public JsonElement Metadata { get; set; } = JsonDefaults.Object();
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
@@ -218,9 +223,142 @@ public sealed class TenantUsageRecord : Entity
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
public sealed class CommerceRefundRequest : AuditableTenantEntity
|
||||
{
|
||||
public Guid OrderId { get; set; }
|
||||
public Guid? PaymentId { get; set; }
|
||||
public Guid? RequestedBy { get; set; }
|
||||
public Guid? ReviewedBy { get; set; }
|
||||
public Guid? ProcessedBy { get; set; }
|
||||
public string RefundNo { get; set; } = string.Empty;
|
||||
public string? Provider { get; set; }
|
||||
public string? ProviderRefundNo { get; set; }
|
||||
public CommerceRefundStatus Status { get; set; } = CommerceRefundStatus.Requested;
|
||||
public int AmountCents { get; set; }
|
||||
public string? Reason { get; set; }
|
||||
public RefundEntitlementAction EntitlementAction { get; set; } = RefundEntitlementAction.RevokeOnSuccess;
|
||||
public DateTimeOffset RequestedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
public DateTimeOffset? ReviewedAt { get; set; }
|
||||
public DateTimeOffset? ProcessedAt { get; set; }
|
||||
public DateTimeOffset? SucceededAt { get; set; }
|
||||
public DateTimeOffset? FailedAt { get; set; }
|
||||
public DateTimeOffset? CancelledAt { get; set; }
|
||||
public string? FailureReason { get; set; }
|
||||
public JsonElement Metadata { get; set; } = JsonDefaults.Object();
|
||||
}
|
||||
|
||||
public sealed class CommerceRefundEvent : Entity
|
||||
{
|
||||
public Guid TenantId { get; set; }
|
||||
public Guid RefundRequestId { get; set; }
|
||||
public CommerceRefundStatus? FromStatus { get; set; }
|
||||
public CommerceRefundStatus ToStatus { get; set; } = CommerceRefundStatus.Requested;
|
||||
public string EventType { get; set; } = string.Empty;
|
||||
public Guid? ActorUserId { get; set; }
|
||||
public JsonElement Details { get; set; } = JsonDefaults.Object();
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
public sealed class CommerceReconciliationBatch : AuditableTenantEntity
|
||||
{
|
||||
public Guid? CreatedBy { get; set; }
|
||||
public string Provider { get; set; } = string.Empty;
|
||||
public DateOnly BillDate { get; set; }
|
||||
public ReconciliationBillType BillType { get; set; } = ReconciliationBillType.Combined;
|
||||
public ReconciliationSource Source { get; set; } = ReconciliationSource.ManualUpload;
|
||||
public string? SourceName { get; set; }
|
||||
public string SourceHash { get; set; } = string.Empty;
|
||||
public ReconciliationBatchStatus Status { get; set; } = ReconciliationBatchStatus.Completed;
|
||||
public int TotalCount { get; set; }
|
||||
public int MatchedCount { get; set; }
|
||||
public int MismatchCount { get; set; }
|
||||
public int MissingLocalCount { get; set; }
|
||||
public int MissingProviderCount { get; set; }
|
||||
public int DuplicateCount { get; set; }
|
||||
public int IgnoredCount { get; set; }
|
||||
public int AmountCents { get; set; }
|
||||
public int RefundAmountCents { get; set; }
|
||||
public int FeeCents { get; set; }
|
||||
public DateTimeOffset? CompletedAt { get; set; }
|
||||
public string? Error { get; set; }
|
||||
public JsonElement Metadata { get; set; } = JsonDefaults.Object();
|
||||
}
|
||||
|
||||
public sealed class CommerceReconciliationItem : Entity
|
||||
{
|
||||
public Guid TenantId { get; set; }
|
||||
public Guid BatchId { get; set; }
|
||||
public Guid? OrderId { get; set; }
|
||||
public Guid? PaymentId { get; set; }
|
||||
public Guid? RefundRequestId { get; set; }
|
||||
public int RowNo { get; set; }
|
||||
public string Provider { get; set; } = string.Empty;
|
||||
public ReconciliationTransactionType TransactionType { get; set; } = ReconciliationTransactionType.Payment;
|
||||
public string? ProviderTradeNo { get; set; }
|
||||
public string? ProviderRefundNo { get; set; }
|
||||
public string? OrderNo { get; set; }
|
||||
public string? RefundNo { get; set; }
|
||||
public int AmountCents { get; set; }
|
||||
public int RefundAmountCents { get; set; }
|
||||
public int FeeCents { get; set; }
|
||||
public DateTimeOffset? PaidAt { get; set; }
|
||||
public DateTimeOffset? RefundedAt { get; set; }
|
||||
public string? ProviderStatus { get; set; }
|
||||
public string? LocalStatus { get; set; }
|
||||
public ReconciliationMatchStatus MatchStatus { get; set; } = ReconciliationMatchStatus.Matched;
|
||||
public NotificationSeverity Severity { get; set; } = NotificationSeverity.Info;
|
||||
public string? IssueCode { get; set; }
|
||||
public JsonElement Details { get; set; } = JsonDefaults.Object();
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
public sealed class CommerceReconciliationIssue : AuditableTenantEntity
|
||||
{
|
||||
public Guid? BatchId { get; set; }
|
||||
public Guid? ItemId { get; set; }
|
||||
public Guid? OrderId { get; set; }
|
||||
public Guid? PaymentId { get; set; }
|
||||
public Guid? RefundRequestId { get; set; }
|
||||
public Guid? AssignedTo { get; set; }
|
||||
public Guid? CreatedBy { get; set; }
|
||||
public Guid? ResolvedBy { get; set; }
|
||||
public string IssueNo { get; set; } = string.Empty;
|
||||
public string Provider { get; set; } = string.Empty;
|
||||
public ReconciliationTransactionType TransactionType { get; set; } = ReconciliationTransactionType.Payment;
|
||||
public string? IssueCode { get; set; }
|
||||
public ReconciliationIssueMatchStatus MatchStatus { get; set; } = ReconciliationIssueMatchStatus.AmountMismatch;
|
||||
public NotificationSeverity Severity { get; set; } = NotificationSeverity.Warning;
|
||||
public ReconciliationIssueStatus Status { get; set; } = ReconciliationIssueStatus.Open;
|
||||
public ReconciliationResolutionType ResolutionType { get; set; } = ReconciliationResolutionType.None;
|
||||
public string? OrderNo { get; set; }
|
||||
public string? RefundNo { get; set; }
|
||||
public string? ProviderTradeNo { get; set; }
|
||||
public string? ProviderRefundNo { get; set; }
|
||||
public int AmountCents { get; set; }
|
||||
public int RefundAmountCents { get; set; }
|
||||
public DateTimeOffset? ResolvedAt { get; set; }
|
||||
public DateTimeOffset? DueAt { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public string? ResolutionNote { get; set; }
|
||||
public JsonElement Metadata { get; set; } = JsonDefaults.Object();
|
||||
}
|
||||
|
||||
public sealed class CommerceReconciliationIssueEvent : Entity
|
||||
{
|
||||
public Guid TenantId { get; set; }
|
||||
public Guid IssueId { get; set; }
|
||||
public ReconciliationIssueStatus? FromStatus { get; set; }
|
||||
public ReconciliationIssueStatus? ToStatus { get; set; }
|
||||
public string EventType { get; set; } = string.Empty;
|
||||
public Guid? ActorUserId { get; set; }
|
||||
public string? Note { get; set; }
|
||||
public JsonElement Details { get; set; } = JsonDefaults.Object();
|
||||
public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
|
||||
public enum ProductType { Material, Course, Service, Link, Other }
|
||||
public enum OrderStatus { Pending, Paid, Failed, Closed, Refunded }
|
||||
public enum PaymentStatus { Pending, Paid, Failed, Cancelled, Refunded }
|
||||
public enum OrderStatus { Pending, Paid, Failed, Closed, PartiallyRefunded, Refunded }
|
||||
public enum PaymentStatus { Pending, Paid, Failed, Cancelled, PartiallyRefunded, Refunded }
|
||||
public enum EntitlementScopeType { Tenant, Region, Module, Subject, QuestionBank }
|
||||
public enum EntitlementStatus { Active, Revoked, Expired }
|
||||
public enum DiscountType { Percent, Fixed }
|
||||
@@ -228,3 +366,14 @@ public enum CouponRedemptionStatus { Claimed, Used, Expired, Cancelled }
|
||||
public enum TenantPaymentMode { PlatformCollect, TenantCollect, ServiceProvider }
|
||||
public enum TenantPaymentAccountStatus { Active, Disabled, Pending }
|
||||
public enum TenantSubscriptionStatus { Trial, Active, PastDue, Cancelled }
|
||||
public enum CommerceRefundStatus { Requested, Approved, Processing, Succeeded, Failed, Rejected, Cancelled }
|
||||
public enum RefundEntitlementAction { None, RevokeOnSuccess }
|
||||
public enum ReconciliationBillType { Payment, Refund, Combined }
|
||||
public enum ReconciliationSource { ManualUpload, ProviderDownload, Api, Worker }
|
||||
public enum ReconciliationBatchStatus { Preview, Pending, Processing, Completed, CompletedWithIssues, Failed }
|
||||
public enum ReconciliationTransactionType { Payment, Refund }
|
||||
public enum ReconciliationMatchStatus { Matched, AmountMismatch, StatusMismatch, MissingLocal, MissingProvider, Duplicate, Ignored }
|
||||
public enum ReconciliationIssueMatchStatus { AmountMismatch, StatusMismatch, MissingLocal, MissingProvider, Duplicate }
|
||||
public enum NotificationSeverity { Info, Warning, Error, Critical }
|
||||
public enum ReconciliationIssueStatus { Open, Investigating, Resolved, Ignored, Escalated }
|
||||
public enum ReconciliationResolutionType { None, ProviderConfirmed, LocalCorrected, ManualAdjustment, FalsePositive, Duplicate, WriteOff }
|
||||
|
||||
@@ -77,7 +77,11 @@ internal sealed class OrderConfiguration : IEntityTypeConfiguration<Order>
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.OrderNo }).IsUnique();
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.LegacyId }).IsUnique();
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.UserId, entity.CreatedAt });
|
||||
builder.ToTable(table => table.HasCheckConstraint("ck_orders_amount", "amount_cents >= 0"));
|
||||
builder.ToTable(table =>
|
||||
{
|
||||
table.HasCheckConstraint("ck_orders_amount", "amount_cents >= 0");
|
||||
table.HasCheckConstraint("ck_orders_refunded_amount", "refunded_amount_cents >= 0");
|
||||
});
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.UserId).OnDelete(DeleteBehavior.SetNull);
|
||||
builder.HasOne<SvipPlan>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.PlanId })
|
||||
@@ -132,7 +136,11 @@ internal sealed class PaymentConfiguration : IEntityTypeConfiguration<Payment>
|
||||
builder.HasIndex(entity => new { entity.Provider, entity.ProviderTradeNo })
|
||||
.IsUnique()
|
||||
.HasFilter("provider_trade_no is not null");
|
||||
builder.ToTable(table => table.HasCheckConstraint("ck_payments_amount", "amount_cents >= 0"));
|
||||
builder.ToTable(table =>
|
||||
{
|
||||
table.HasCheckConstraint("ck_payments_amount", "amount_cents >= 0");
|
||||
table.HasCheckConstraint("ck_payments_refunded_amount", "refunded_amount_cents >= 0");
|
||||
});
|
||||
builder.HasOne<Order>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.OrderId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
@@ -171,12 +179,14 @@ internal sealed class EntitlementConfiguration : IEntityTypeConfiguration<Entitl
|
||||
builder.Property(entity => entity.SourceType).HasMaxLength(100);
|
||||
builder.Property(entity => entity.LegacySourceId).HasMaxLength(64);
|
||||
builder.Property(entity => entity.Status).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.RevokedReason).HasMaxLength(1000);
|
||||
builder.Property(entity => entity.Metadata).IsJson("{}");
|
||||
builder.Property(entity => entity.StartsAt).HasDefaultValueSql("now()");
|
||||
builder.Property(entity => entity.CreatedAt).HasDefaultValueSql("now()");
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.UserId, entity.Status, entity.ExpiresAt });
|
||||
builder.HasOne<Tenant>().WithMany().HasForeignKey(entity => entity.TenantId).OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.UserId).OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.RevokedBy).OnDelete(DeleteBehavior.SetNull);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,3 +341,205 @@ internal sealed class TenantUsageRecordConfiguration : IEntityTypeConfiguration<
|
||||
builder.HasOne<Tenant>().WithMany().HasForeignKey(entity => entity.TenantId).OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CommerceRefundRequestConfiguration : IEntityTypeConfiguration<CommerceRefundRequest>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<CommerceRefundRequest> builder)
|
||||
{
|
||||
builder.ConfigureTenantEntity("commerce_refund_requests");
|
||||
builder.ConfigureTimestamps();
|
||||
builder.Property(entity => entity.RefundNo).HasMaxLength(100);
|
||||
builder.Property(entity => entity.Provider).HasMaxLength(50);
|
||||
builder.Property(entity => entity.ProviderRefundNo).HasMaxLength(200);
|
||||
builder.Property(entity => entity.Status).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.EntitlementAction).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.Metadata).IsJson("{}");
|
||||
builder.Property(entity => entity.RequestedAt).HasDefaultValueSql("now()");
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.RefundNo }).IsUnique();
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.OrderId, entity.CreatedAt });
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.Status, entity.CreatedAt });
|
||||
builder.ToTable(table => table.HasCheckConstraint("ck_commerce_refund_requests_amount", "amount_cents > 0"));
|
||||
builder.HasOne<Order>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.OrderId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasOne<Payment>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.PaymentId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.RequestedBy).OnDelete(DeleteBehavior.SetNull);
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.ReviewedBy).OnDelete(DeleteBehavior.SetNull);
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.ProcessedBy).OnDelete(DeleteBehavior.SetNull);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CommerceRefundEventConfiguration : IEntityTypeConfiguration<CommerceRefundEvent>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<CommerceRefundEvent> builder)
|
||||
{
|
||||
builder.ConfigureEntity("commerce_refund_events");
|
||||
builder.HasAlternateKey(entity => new { entity.TenantId, entity.Id });
|
||||
builder.Property(entity => entity.FromStatus).HasNullableSnakeCaseEnum();
|
||||
builder.Property(entity => entity.ToStatus).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.EventType).HasMaxLength(100);
|
||||
builder.Property(entity => entity.Details).IsJson("{}");
|
||||
builder.Property(entity => entity.CreatedAt).HasDefaultValueSql("now()");
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.RefundRequestId, entity.CreatedAt });
|
||||
builder.HasOne<Tenant>().WithMany().HasForeignKey(entity => entity.TenantId).OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasOne<CommerceRefundRequest>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.RefundRequestId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.ActorUserId).OnDelete(DeleteBehavior.SetNull);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CommerceReconciliationBatchConfiguration : IEntityTypeConfiguration<CommerceReconciliationBatch>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<CommerceReconciliationBatch> builder)
|
||||
{
|
||||
builder.ConfigureTenantEntity("commerce_reconciliation_batches");
|
||||
builder.ConfigureTimestamps();
|
||||
builder.Property(entity => entity.Provider).HasMaxLength(50);
|
||||
builder.Property(entity => entity.BillType).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.Source).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.SourceName).HasMaxLength(300);
|
||||
builder.Property(entity => entity.SourceHash).HasMaxLength(200);
|
||||
builder.Property(entity => entity.Status).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.Metadata).IsJson("{}");
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.Provider, entity.BillDate, entity.CreatedAt });
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.Status, entity.CreatedAt });
|
||||
builder.ToTable(table =>
|
||||
{
|
||||
table.HasCheckConstraint("ck_commerce_reconciliation_batches_counts", "total_count >= 0 and matched_count >= 0 and mismatch_count >= 0 and missing_local_count >= 0 and missing_provider_count >= 0 and duplicate_count >= 0 and ignored_count >= 0");
|
||||
table.HasCheckConstraint("ck_commerce_reconciliation_batches_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");
|
||||
});
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.CreatedBy).OnDelete(DeleteBehavior.SetNull);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CommerceReconciliationItemConfiguration : IEntityTypeConfiguration<CommerceReconciliationItem>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<CommerceReconciliationItem> builder)
|
||||
{
|
||||
builder.ConfigureEntity("commerce_reconciliation_items");
|
||||
builder.HasAlternateKey(entity => new { entity.TenantId, entity.Id });
|
||||
builder.Property(entity => entity.Provider).HasMaxLength(50);
|
||||
builder.Property(entity => entity.TransactionType).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.ProviderTradeNo).HasMaxLength(200);
|
||||
builder.Property(entity => entity.ProviderRefundNo).HasMaxLength(200);
|
||||
builder.Property(entity => entity.OrderNo).HasMaxLength(100);
|
||||
builder.Property(entity => entity.RefundNo).HasMaxLength(100);
|
||||
builder.Property(entity => entity.ProviderStatus).HasMaxLength(100);
|
||||
builder.Property(entity => entity.LocalStatus).HasMaxLength(100);
|
||||
builder.Property(entity => entity.MatchStatus).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.Severity).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.IssueCode).HasMaxLength(100);
|
||||
builder.Property(entity => entity.Details).IsJson("{}");
|
||||
builder.Property(entity => entity.CreatedAt).HasDefaultValueSql("now()");
|
||||
builder.HasIndex(entity => new { entity.BatchId, entity.RowNo }).IsUnique();
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.BatchId, entity.MatchStatus, entity.RowNo });
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.OrderNo, entity.CreatedAt });
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.RefundNo, entity.ProviderRefundNo, entity.CreatedAt });
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.Provider, entity.ProviderTradeNo, entity.CreatedAt });
|
||||
builder.ToTable(table =>
|
||||
{
|
||||
table.HasCheckConstraint("ck_commerce_reconciliation_items_row", "row_no > 0");
|
||||
table.HasCheckConstraint("ck_commerce_reconciliation_items_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");
|
||||
});
|
||||
builder.HasOne<Tenant>().WithMany().HasForeignKey(entity => entity.TenantId).OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasOne<CommerceReconciliationBatch>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.BatchId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasOne<Order>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.OrderId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne<Payment>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.PaymentId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne<CommerceRefundRequest>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.RefundRequestId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CommerceReconciliationIssueConfiguration : IEntityTypeConfiguration<CommerceReconciliationIssue>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<CommerceReconciliationIssue> builder)
|
||||
{
|
||||
builder.ConfigureTenantEntity("commerce_reconciliation_issues");
|
||||
builder.ConfigureTimestamps();
|
||||
builder.Property(entity => entity.IssueNo).HasMaxLength(100);
|
||||
builder.Property(entity => entity.Provider).HasMaxLength(50);
|
||||
builder.Property(entity => entity.TransactionType).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.IssueCode).HasMaxLength(100);
|
||||
builder.Property(entity => entity.MatchStatus).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.Severity).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.Status).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.ResolutionType).HasSnakeCaseEnum();
|
||||
builder.Property(entity => entity.OrderNo).HasMaxLength(100);
|
||||
builder.Property(entity => entity.RefundNo).HasMaxLength(100);
|
||||
builder.Property(entity => entity.ProviderTradeNo).HasMaxLength(200);
|
||||
builder.Property(entity => entity.ProviderRefundNo).HasMaxLength(200);
|
||||
builder.Property(entity => entity.Summary).HasMaxLength(1000);
|
||||
builder.Property(entity => entity.Metadata).IsJson("{}");
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.IssueNo }).IsUnique();
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.ItemId })
|
||||
.IsUnique()
|
||||
.HasFilter("item_id is not null and status in ('open', 'investigating', 'escalated')");
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.Status, entity.Severity, entity.CreatedAt });
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.AssignedTo, entity.Status, entity.DueAt });
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.BatchId, entity.Status, entity.CreatedAt });
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.OrderNo, entity.CreatedAt });
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.PaymentId, entity.CreatedAt });
|
||||
builder.ToTable(table => table.HasCheckConstraint("ck_commerce_reconciliation_issues_amounts", "amount_cents >= 0 and refund_amount_cents >= 0"));
|
||||
builder.HasOne<CommerceReconciliationBatch>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.BatchId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne<CommerceReconciliationItem>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.ItemId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne<Order>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.OrderId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne<Payment>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.PaymentId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne<CommerceRefundRequest>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.RefundRequestId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.AssignedTo).OnDelete(DeleteBehavior.SetNull);
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.CreatedBy).OnDelete(DeleteBehavior.SetNull);
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.ResolvedBy).OnDelete(DeleteBehavior.SetNull);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class CommerceReconciliationIssueEventConfiguration : IEntityTypeConfiguration<CommerceReconciliationIssueEvent>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<CommerceReconciliationIssueEvent> builder)
|
||||
{
|
||||
builder.ConfigureEntity("commerce_reconciliation_issue_events");
|
||||
builder.HasAlternateKey(entity => new { entity.TenantId, entity.Id });
|
||||
builder.Property(entity => entity.FromStatus).HasNullableSnakeCaseEnum();
|
||||
builder.Property(entity => entity.ToStatus).HasNullableSnakeCaseEnum();
|
||||
builder.Property(entity => entity.EventType).HasMaxLength(100);
|
||||
builder.Property(entity => entity.Details).IsJson("{}");
|
||||
builder.Property(entity => entity.CreatedAt).HasDefaultValueSql("now()");
|
||||
builder.HasIndex(entity => new { entity.TenantId, entity.IssueId, entity.CreatedAt });
|
||||
builder.HasOne<Tenant>().WithMany().HasForeignKey(entity => entity.TenantId).OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasOne<CommerceReconciliationIssue>().WithMany()
|
||||
.HasForeignKey(entity => new { entity.TenantId, entity.IssueId })
|
||||
.HasPrincipalKey(entity => new { entity.TenantId, entity.Id })
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasOne<User>().WithMany().HasForeignKey(entity => entity.ActorUserId).OnDelete(DeleteBehavior.SetNull);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,669 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Tiku.Infrastructure.Persistence.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddCommerceRefundAndReconciliationPersistence : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "refunded_amount_cents",
|
||||
table: "payments",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "refunded_amount_cents",
|
||||
table: "orders",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.AddColumn<DateTimeOffset>(
|
||||
name: "revoked_at",
|
||||
table: "entitlements",
|
||||
type: "timestamp with time zone",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "revoked_by",
|
||||
table: "entitlements",
|
||||
type: "uuid",
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "revoked_reason",
|
||||
table: "entitlements",
|
||||
type: "character varying(1000)",
|
||||
maxLength: 1000,
|
||||
nullable: true);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "commerce_reconciliation_batches",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
created_by = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
provider = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
bill_date = table.Column<DateOnly>(type: "date", nullable: false),
|
||||
bill_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
source = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
source_name = table.Column<string>(type: "character varying(300)", maxLength: 300, nullable: true),
|
||||
source_hash = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
|
||||
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
total_count = table.Column<int>(type: "integer", nullable: false),
|
||||
matched_count = table.Column<int>(type: "integer", nullable: false),
|
||||
mismatch_count = table.Column<int>(type: "integer", nullable: false),
|
||||
missing_local_count = table.Column<int>(type: "integer", nullable: false),
|
||||
missing_provider_count = table.Column<int>(type: "integer", nullable: false),
|
||||
duplicate_count = table.Column<int>(type: "integer", nullable: false),
|
||||
ignored_count = table.Column<int>(type: "integer", nullable: false),
|
||||
amount_cents = table.Column<int>(type: "integer", nullable: false),
|
||||
refund_amount_cents = table.Column<int>(type: "integer", nullable: false),
|
||||
fee_cents = table.Column<int>(type: "integer", nullable: false),
|
||||
completed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
error = table.Column<string>(type: "text", nullable: true),
|
||||
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
||||
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
||||
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_commerce_reconciliation_batches", x => x.id);
|
||||
table.UniqueConstraint("ak_commerce_reconciliation_batches_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.CheckConstraint("ck_commerce_reconciliation_batches_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");
|
||||
table.CheckConstraint("ck_commerce_reconciliation_batches_counts", "total_count >= 0 and matched_count >= 0 and mismatch_count >= 0 and missing_local_count >= 0 and missing_provider_count >= 0 and duplicate_count >= 0 and ignored_count >= 0");
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_batches_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_batches_users_created_by",
|
||||
column: x => x.created_by,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "commerce_refund_requests",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
order_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
payment_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
requested_by = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
reviewed_by = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
processed_by = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
refund_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
provider = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: true),
|
||||
provider_refund_no = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
||||
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
amount_cents = table.Column<int>(type: "integer", nullable: false),
|
||||
reason = table.Column<string>(type: "text", nullable: true),
|
||||
entitlement_action = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
requested_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
||||
reviewed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
processed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
succeeded_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
failed_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
cancelled_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
failure_reason = table.Column<string>(type: "text", nullable: true),
|
||||
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
||||
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
||||
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_commerce_refund_requests", x => x.id);
|
||||
table.UniqueConstraint("ak_commerce_refund_requests_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.CheckConstraint("ck_commerce_refund_requests_amount", "amount_cents > 0");
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_refund_requests_orders_tenant_id_order_id",
|
||||
columns: x => new { x.tenant_id, x.order_id },
|
||||
principalTable: "orders",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_refund_requests_payments_tenant_id_payment_id",
|
||||
columns: x => new { x.tenant_id, x.payment_id },
|
||||
principalTable: "payments",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_refund_requests_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_refund_requests_users_processed_by",
|
||||
column: x => x.processed_by,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_refund_requests_users_requested_by",
|
||||
column: x => x.requested_by,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_refund_requests_users_reviewed_by",
|
||||
column: x => x.reviewed_by,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "commerce_reconciliation_items",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
batch_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
order_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
payment_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
refund_request_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
row_no = table.Column<int>(type: "integer", nullable: false),
|
||||
provider = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
transaction_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
provider_trade_no = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
||||
provider_refund_no = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
||||
order_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
||||
refund_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
||||
amount_cents = table.Column<int>(type: "integer", nullable: false),
|
||||
refund_amount_cents = table.Column<int>(type: "integer", nullable: false),
|
||||
fee_cents = table.Column<int>(type: "integer", nullable: false),
|
||||
paid_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
refunded_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
provider_status = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
||||
local_status = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
||||
match_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
severity = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
issue_code = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
||||
details = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_commerce_reconciliation_items", x => x.id);
|
||||
table.UniqueConstraint("ak_commerce_reconciliation_items_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.CheckConstraint("ck_commerce_reconciliation_items_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");
|
||||
table.CheckConstraint("ck_commerce_reconciliation_items_row", "row_no > 0");
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_items_commerce_reconciliation_batch~",
|
||||
columns: x => new { x.tenant_id, x.batch_id },
|
||||
principalTable: "commerce_reconciliation_batches",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_items_commerce_refund_requests_tena~",
|
||||
columns: x => new { x.tenant_id, x.refund_request_id },
|
||||
principalTable: "commerce_refund_requests",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_items_orders_tenant_id_order_id",
|
||||
columns: x => new { x.tenant_id, x.order_id },
|
||||
principalTable: "orders",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_items_payments_tenant_id_payment_id",
|
||||
columns: x => new { x.tenant_id, x.payment_id },
|
||||
principalTable: "payments",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_items_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "commerce_refund_events",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
refund_request_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
from_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
||||
to_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
event_type = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
actor_user_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
details = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_commerce_refund_events", x => x.id);
|
||||
table.UniqueConstraint("ak_commerce_refund_events_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_refund_events_commerce_refund_requests_tenant_id_r~",
|
||||
columns: x => new { x.tenant_id, x.refund_request_id },
|
||||
principalTable: "commerce_refund_requests",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_refund_events_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_refund_events_users_actor_user_id",
|
||||
column: x => x.actor_user_id,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "commerce_reconciliation_issues",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
batch_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
item_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
order_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
payment_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
refund_request_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
assigned_to = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
created_by = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
resolved_by = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
issue_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
provider = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
|
||||
transaction_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
issue_code = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
||||
match_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
severity = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
resolution_type = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
order_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
||||
refund_no = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
|
||||
provider_trade_no = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
||||
provider_refund_no = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: true),
|
||||
amount_cents = table.Column<int>(type: "integer", nullable: false),
|
||||
refund_amount_cents = table.Column<int>(type: "integer", nullable: false),
|
||||
resolved_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
due_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
|
||||
summary = table.Column<string>(type: "character varying(1000)", maxLength: 1000, nullable: true),
|
||||
resolution_note = table.Column<string>(type: "text", nullable: true),
|
||||
metadata = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
||||
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"),
|
||||
updated_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_commerce_reconciliation_issues", x => x.id);
|
||||
table.UniqueConstraint("ak_commerce_reconciliation_issues_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.CheckConstraint("ck_commerce_reconciliation_issues_amounts", "amount_cents >= 0 and refund_amount_cents >= 0");
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issues_commerce_reconciliation_batc~",
|
||||
columns: x => new { x.tenant_id, x.batch_id },
|
||||
principalTable: "commerce_reconciliation_batches",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issues_commerce_reconciliation_item~",
|
||||
columns: x => new { x.tenant_id, x.item_id },
|
||||
principalTable: "commerce_reconciliation_items",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issues_commerce_refund_requests_ten~",
|
||||
columns: x => new { x.tenant_id, x.refund_request_id },
|
||||
principalTable: "commerce_refund_requests",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issues_orders_tenant_id_order_id",
|
||||
columns: x => new { x.tenant_id, x.order_id },
|
||||
principalTable: "orders",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issues_payments_tenant_id_payment_id",
|
||||
columns: x => new { x.tenant_id, x.payment_id },
|
||||
principalTable: "payments",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issues_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issues_users_assigned_to",
|
||||
column: x => x.assigned_to,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issues_users_created_by",
|
||||
column: x => x.created_by,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issues_users_resolved_by",
|
||||
column: x => x.resolved_by,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "commerce_reconciliation_issue_events",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"),
|
||||
tenant_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
issue_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
from_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
||||
to_status = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: true),
|
||||
event_type = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
|
||||
actor_user_id = table.Column<Guid>(type: "uuid", nullable: true),
|
||||
note = table.Column<string>(type: "text", nullable: true),
|
||||
details = table.Column<JsonElement>(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("pk_commerce_reconciliation_issue_events", x => x.id);
|
||||
table.UniqueConstraint("ak_commerce_reconciliation_issue_events_tenant_id_id", x => new { x.tenant_id, x.id });
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issue_events_commerce_reconciliatio~",
|
||||
columns: x => new { x.tenant_id, x.issue_id },
|
||||
principalTable: "commerce_reconciliation_issues",
|
||||
principalColumns: new[] { "tenant_id", "id" },
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issue_events_tenants_tenant_id",
|
||||
column: x => x.tenant_id,
|
||||
principalTable: "tenants",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "fk_commerce_reconciliation_issue_events_users_actor_user_id",
|
||||
column: x => x.actor_user_id,
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
});
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "ck_payments_refunded_amount",
|
||||
table: "payments",
|
||||
sql: "refunded_amount_cents >= 0");
|
||||
|
||||
migrationBuilder.AddCheckConstraint(
|
||||
name: "ck_orders_refunded_amount",
|
||||
table: "orders",
|
||||
sql: "refunded_amount_cents >= 0");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_entitlements_revoked_by",
|
||||
table: "entitlements",
|
||||
column: "revoked_by");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_batches_created_by",
|
||||
table: "commerce_reconciliation_batches",
|
||||
column: "created_by");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_batches_tenant_id_provider_bill_dat~",
|
||||
table: "commerce_reconciliation_batches",
|
||||
columns: new[] { "tenant_id", "provider", "bill_date", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_batches_tenant_id_status_created_at",
|
||||
table: "commerce_reconciliation_batches",
|
||||
columns: new[] { "tenant_id", "status", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issue_events_actor_user_id",
|
||||
table: "commerce_reconciliation_issue_events",
|
||||
column: "actor_user_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issue_events_tenant_id_issue_id_cre~",
|
||||
table: "commerce_reconciliation_issue_events",
|
||||
columns: new[] { "tenant_id", "issue_id", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_assigned_to",
|
||||
table: "commerce_reconciliation_issues",
|
||||
column: "assigned_to");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_created_by",
|
||||
table: "commerce_reconciliation_issues",
|
||||
column: "created_by");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_resolved_by",
|
||||
table: "commerce_reconciliation_issues",
|
||||
column: "resolved_by");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_tenant_id_assigned_to_status~",
|
||||
table: "commerce_reconciliation_issues",
|
||||
columns: new[] { "tenant_id", "assigned_to", "status", "due_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_tenant_id_batch_id_status_cr~",
|
||||
table: "commerce_reconciliation_issues",
|
||||
columns: new[] { "tenant_id", "batch_id", "status", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_tenant_id_issue_no",
|
||||
table: "commerce_reconciliation_issues",
|
||||
columns: new[] { "tenant_id", "issue_no" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_tenant_id_item_id",
|
||||
table: "commerce_reconciliation_issues",
|
||||
columns: new[] { "tenant_id", "item_id" },
|
||||
unique: true,
|
||||
filter: "item_id is not null and status in ('open', 'investigating', 'escalated')");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_tenant_id_order_id",
|
||||
table: "commerce_reconciliation_issues",
|
||||
columns: new[] { "tenant_id", "order_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_tenant_id_order_no_created_at",
|
||||
table: "commerce_reconciliation_issues",
|
||||
columns: new[] { "tenant_id", "order_no", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_tenant_id_payment_id_created~",
|
||||
table: "commerce_reconciliation_issues",
|
||||
columns: new[] { "tenant_id", "payment_id", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_tenant_id_refund_request_id",
|
||||
table: "commerce_reconciliation_issues",
|
||||
columns: new[] { "tenant_id", "refund_request_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_issues_tenant_id_status_severity_cr~",
|
||||
table: "commerce_reconciliation_issues",
|
||||
columns: new[] { "tenant_id", "status", "severity", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_items_batch_id_row_no",
|
||||
table: "commerce_reconciliation_items",
|
||||
columns: new[] { "batch_id", "row_no" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_items_tenant_id_batch_id_match_stat~",
|
||||
table: "commerce_reconciliation_items",
|
||||
columns: new[] { "tenant_id", "batch_id", "match_status", "row_no" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_items_tenant_id_order_id",
|
||||
table: "commerce_reconciliation_items",
|
||||
columns: new[] { "tenant_id", "order_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_items_tenant_id_order_no_created_at",
|
||||
table: "commerce_reconciliation_items",
|
||||
columns: new[] { "tenant_id", "order_no", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_items_tenant_id_payment_id",
|
||||
table: "commerce_reconciliation_items",
|
||||
columns: new[] { "tenant_id", "payment_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_items_tenant_id_provider_provider_t~",
|
||||
table: "commerce_reconciliation_items",
|
||||
columns: new[] { "tenant_id", "provider", "provider_trade_no", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_items_tenant_id_refund_no_provider_~",
|
||||
table: "commerce_reconciliation_items",
|
||||
columns: new[] { "tenant_id", "refund_no", "provider_refund_no", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_reconciliation_items_tenant_id_refund_request_id",
|
||||
table: "commerce_reconciliation_items",
|
||||
columns: new[] { "tenant_id", "refund_request_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_refund_events_actor_user_id",
|
||||
table: "commerce_refund_events",
|
||||
column: "actor_user_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_refund_events_tenant_id_refund_request_id_created_~",
|
||||
table: "commerce_refund_events",
|
||||
columns: new[] { "tenant_id", "refund_request_id", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_refund_requests_processed_by",
|
||||
table: "commerce_refund_requests",
|
||||
column: "processed_by");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_refund_requests_requested_by",
|
||||
table: "commerce_refund_requests",
|
||||
column: "requested_by");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_refund_requests_reviewed_by",
|
||||
table: "commerce_refund_requests",
|
||||
column: "reviewed_by");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_refund_requests_tenant_id_order_id_created_at",
|
||||
table: "commerce_refund_requests",
|
||||
columns: new[] { "tenant_id", "order_id", "created_at" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_refund_requests_tenant_id_payment_id",
|
||||
table: "commerce_refund_requests",
|
||||
columns: new[] { "tenant_id", "payment_id" });
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_refund_requests_tenant_id_refund_no",
|
||||
table: "commerce_refund_requests",
|
||||
columns: new[] { "tenant_id", "refund_no" },
|
||||
unique: true);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_commerce_refund_requests_tenant_id_status_created_at",
|
||||
table: "commerce_refund_requests",
|
||||
columns: new[] { "tenant_id", "status", "created_at" });
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "fk_entitlements_users_revoked_by",
|
||||
table: "entitlements",
|
||||
column: "revoked_by",
|
||||
principalTable: "users",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.SetNull);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "fk_entitlements_users_revoked_by",
|
||||
table: "entitlements");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "commerce_reconciliation_issue_events");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "commerce_refund_events");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "commerce_reconciliation_issues");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "commerce_reconciliation_items");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "commerce_reconciliation_batches");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "commerce_refund_requests");
|
||||
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "ck_payments_refunded_amount",
|
||||
table: "payments");
|
||||
|
||||
migrationBuilder.DropCheckConstraint(
|
||||
name: "ck_orders_refunded_amount",
|
||||
table: "orders");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "ix_entitlements_revoked_by",
|
||||
table: "entitlements");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "refunded_amount_cents",
|
||||
table: "payments");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "refunded_amount_cents",
|
||||
table: "orders");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "revoked_at",
|
||||
table: "entitlements");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "revoked_by",
|
||||
table: "entitlements");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "revoked_reason",
|
||||
table: "entitlements");
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -93,6 +93,12 @@ public sealed class TikuDbContext(DbContextOptions<TikuDbContext> options) : DbC
|
||||
public DbSet<TenantPaymentAccount> TenantPaymentAccounts => Set<TenantPaymentAccount>();
|
||||
public DbSet<TenantSubscription> TenantSubscriptions => Set<TenantSubscription>();
|
||||
public DbSet<TenantUsageRecord> TenantUsageRecords => Set<TenantUsageRecord>();
|
||||
public DbSet<CommerceRefundRequest> CommerceRefundRequests => Set<CommerceRefundRequest>();
|
||||
public DbSet<CommerceRefundEvent> CommerceRefundEvents => Set<CommerceRefundEvent>();
|
||||
public DbSet<CommerceReconciliationBatch> CommerceReconciliationBatches => Set<CommerceReconciliationBatch>();
|
||||
public DbSet<CommerceReconciliationItem> CommerceReconciliationItems => Set<CommerceReconciliationItem>();
|
||||
public DbSet<CommerceReconciliationIssue> CommerceReconciliationIssues => Set<CommerceReconciliationIssue>();
|
||||
public DbSet<CommerceReconciliationIssueEvent> CommerceReconciliationIssueEvents => Set<CommerceReconciliationIssueEvent>();
|
||||
public DbSet<ReferralTrack> ReferralTracks => Set<ReferralTrack>();
|
||||
public DbSet<ReferralCode> ReferralCodes => Set<ReferralCode>();
|
||||
public DbSet<ReferralLead> ReferralLeads => Set<ReferralLead>();
|
||||
|
||||
@@ -28,7 +28,7 @@ public sealed class PersistenceModelTests
|
||||
.Select(entity => entity.GetTableName())
|
||||
.ToHashSet(StringComparer.Ordinal);
|
||||
|
||||
Assert.Equal(100, tableNames.Count);
|
||||
Assert.Equal(106, tableNames.Count);
|
||||
Assert.Contains("tenants", tableNames);
|
||||
Assert.Contains("tenant_settings", tableNames);
|
||||
Assert.Contains("content_entries", tableNames);
|
||||
@@ -86,6 +86,12 @@ public sealed class PersistenceModelTests
|
||||
Assert.Contains("tenant_payment_accounts", tableNames);
|
||||
Assert.Contains("tenant_subscriptions", tableNames);
|
||||
Assert.Contains("tenant_usage_records", tableNames);
|
||||
Assert.Contains("commerce_refund_requests", tableNames);
|
||||
Assert.Contains("commerce_refund_events", tableNames);
|
||||
Assert.Contains("commerce_reconciliation_batches", tableNames);
|
||||
Assert.Contains("commerce_reconciliation_items", tableNames);
|
||||
Assert.Contains("commerce_reconciliation_issues", tableNames);
|
||||
Assert.Contains("commerce_reconciliation_issue_events", tableNames);
|
||||
Assert.Contains("referral_tracks", tableNames);
|
||||
Assert.Contains("referral_codes", tableNames);
|
||||
Assert.Contains("referral_leads", tableNames);
|
||||
@@ -484,6 +490,12 @@ public sealed class PersistenceModelTests
|
||||
[InlineData(typeof(TenantPaymentAccount), nameof(TenantPaymentAccount.ConfigPublic), "'{}'::jsonb")]
|
||||
[InlineData(typeof(TenantSubscription), nameof(TenantSubscription.Metadata), "'{}'::jsonb")]
|
||||
[InlineData(typeof(TenantUsageRecord), nameof(TenantUsageRecord.Metadata), "'{}'::jsonb")]
|
||||
[InlineData(typeof(CommerceRefundRequest), nameof(CommerceRefundRequest.Metadata), "'{}'::jsonb")]
|
||||
[InlineData(typeof(CommerceRefundEvent), nameof(CommerceRefundEvent.Details), "'{}'::jsonb")]
|
||||
[InlineData(typeof(CommerceReconciliationBatch), nameof(CommerceReconciliationBatch.Metadata), "'{}'::jsonb")]
|
||||
[InlineData(typeof(CommerceReconciliationItem), nameof(CommerceReconciliationItem.Details), "'{}'::jsonb")]
|
||||
[InlineData(typeof(CommerceReconciliationIssue), nameof(CommerceReconciliationIssue.Metadata), "'{}'::jsonb")]
|
||||
[InlineData(typeof(CommerceReconciliationIssueEvent), nameof(CommerceReconciliationIssueEvent.Details), "'{}'::jsonb")]
|
||||
public void Commerce_json_properties_are_mapped_to_jsonb(
|
||||
Type entityType,
|
||||
string propertyName,
|
||||
@@ -509,11 +521,27 @@ public sealed class PersistenceModelTests
|
||||
AssertHasUniqueIndex<TenantPaymentAccount>(
|
||||
nameof(TenantPaymentAccount.TenantId),
|
||||
nameof(TenantPaymentAccount.Provider));
|
||||
AssertHasUniqueIndex<CommerceRefundRequest>(
|
||||
nameof(CommerceRefundRequest.TenantId),
|
||||
nameof(CommerceRefundRequest.RefundNo));
|
||||
AssertHasUniqueIndex<CommerceReconciliationItem>(
|
||||
nameof(CommerceReconciliationItem.BatchId),
|
||||
nameof(CommerceReconciliationItem.RowNo));
|
||||
AssertHasUniqueIndex<CommerceReconciliationIssue>(
|
||||
nameof(CommerceReconciliationIssue.TenantId),
|
||||
nameof(CommerceReconciliationIssue.IssueNo));
|
||||
AssertHasUniqueIndex<CommerceReconciliationIssue>(
|
||||
nameof(CommerceReconciliationIssue.TenantId),
|
||||
nameof(CommerceReconciliationIssue.ItemId));
|
||||
|
||||
var amount = context.Model.FindEntityType(typeof(Order))!
|
||||
.FindProperty(nameof(Order.AmountCents))!;
|
||||
Assert.Equal(typeof(int), amount.ClrType);
|
||||
|
||||
var refundedAmount = context.Model.FindEntityType(typeof(Order))!
|
||||
.FindProperty(nameof(Order.RefundedAmountCents))!;
|
||||
Assert.Equal(typeof(int), refundedAmount.ClrType);
|
||||
|
||||
void AssertHasUniqueIndex<TEntity>(params string[] propertyNames)
|
||||
{
|
||||
var indexes = context.Model.FindEntityType(typeof(TEntity))!.GetIndexes();
|
||||
|
||||
Reference in New Issue
Block a user