事务性发件箱模式
This commit is contained in:
1 parent
8da853a351
commit
f007572e7f
30 files changed
+978
-135
No files matched your search
-25
@@ -1,25 +0,0 @@
|
||||
// Copyright (c) HelloShop Corporation. All rights reserved.
|
||||
// See the license file in the project root for more information.
|
||||
|
||||
using HelloShop.EventBus.Abstractions;
|
||||
using HelloShop.OrderingService.Entities.EventLogs;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.EventLogs
|
||||
{
|
||||
public class DistributedEventLogEntityTypeConfiguration : IEntityTypeConfiguration<DistributedEventLog>
|
||||
{
|
||||
private static readonly JsonSerializerOptions s_jsonSerializerOptions = new(JsonSerializerDefaults.Web);
|
||||
|
||||
public void Configure(EntityTypeBuilder<DistributedEventLog> builder)
|
||||
{
|
||||
builder.HasKey(x => x.EventId);
|
||||
builder.Property(x => x.EventTypeName).HasMaxLength(32);
|
||||
builder.Property(x => x.Status).HasConversion<string>();
|
||||
|
||||
builder.Property(x => x.DistributedEvent).HasConversion(v => JsonSerializer.Serialize(v, v.GetType(), s_jsonSerializerOptions), v => JsonSerializer.Deserialize<DistributedEvent>(v, s_jsonSerializerOptions)!);
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+347
@@ -0,0 +1,347 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using HelloShop.OrderingService.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace HelloShop.OrderingService.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(OrderingServiceDbContext))]
|
||||
[Migration("20250328130944_AddEventLogTable")]
|
||||
partial class AddEventLogTable
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "9.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HelloShop.EventBus.Logging.DistributedEventLog", b =>
|
||||
{
|
||||
b.Property<Guid>("EventId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("event_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreationTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("creation_time");
|
||||
|
||||
b.Property<string>("DistributedEvent")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("distributed_event");
|
||||
|
||||
b.Property<string>("EventTypeName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("event_type_name");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<int>("TimesSent")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("times_sent");
|
||||
|
||||
b.Property<Guid>("TransactionId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("transaction_id");
|
||||
|
||||
b.HasKey("EventId")
|
||||
.HasName("pk_distributed_event_log");
|
||||
|
||||
b.ToTable("distributed_event_log", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_buyer");
|
||||
|
||||
b.ToTable("buyer", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Alias")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)")
|
||||
.HasColumnName("alias");
|
||||
|
||||
b.Property<int>("BuyerId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("buyer_id");
|
||||
|
||||
b.Property<string>("CardHolderName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)")
|
||||
.HasColumnName("card_holder_name");
|
||||
|
||||
b.Property<string>("CardNumber")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)")
|
||||
.HasColumnName("card_number");
|
||||
|
||||
b.Property<DateTimeOffset?>("Expiration")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("expiration");
|
||||
|
||||
b.Property<string>("SecurityNumber")
|
||||
.HasMaxLength(6)
|
||||
.HasColumnType("character varying(6)")
|
||||
.HasColumnName("security_number");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_payment_method");
|
||||
|
||||
b.HasIndex("BuyerId")
|
||||
.HasDatabaseName("ix_payment_method_buyer_id");
|
||||
|
||||
b.ToTable("payment_method", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Idempotency.ClientRequest", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("id");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<DateTimeOffset>("Time")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("time");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_client_request");
|
||||
|
||||
b.ToTable("client_request", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuyerId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("buyer_id");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("description");
|
||||
|
||||
b.Property<DateTimeOffset>("OrderDate")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("order_date");
|
||||
|
||||
b.Property<string>("OrderStatus")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("order_status");
|
||||
|
||||
b.Property<int?>("PaymentMethodId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("payment_method_id");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_order");
|
||||
|
||||
b.HasIndex("BuyerId")
|
||||
.HasDatabaseName("ix_order_buyer_id");
|
||||
|
||||
b.HasIndex("PaymentMethodId")
|
||||
.HasDatabaseName("ix_order_payment_method_id");
|
||||
|
||||
b.ToTable("order", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("order_id");
|
||||
|
||||
b.Property<string>("PictureUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)")
|
||||
.HasColumnName("picture_url");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("product_id");
|
||||
|
||||
b.Property<string>("ProductName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)")
|
||||
.HasColumnName("product_name");
|
||||
|
||||
b.Property<decimal>("UnitPrice")
|
||||
.HasColumnType("numeric")
|
||||
.HasColumnName("unit_price");
|
||||
|
||||
b.Property<int>("Units")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("units");
|
||||
|
||||
b.HasKey("Id")
|
||||
.HasName("pk_order_item");
|
||||
|
||||
b.HasIndex("OrderId")
|
||||
.HasDatabaseName("ix_order_item_order_id");
|
||||
|
||||
b.ToTable("order_item", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b =>
|
||||
{
|
||||
b.HasOne("HelloShop.OrderingService.Entities.Buyers.Buyer", null)
|
||||
.WithMany("PaymentMethods")
|
||||
.HasForeignKey("BuyerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_payment_method_buyer_buyer_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b =>
|
||||
{
|
||||
b.HasOne("HelloShop.OrderingService.Entities.Buyers.Buyer", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("BuyerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_order_buyer_buyer_id");
|
||||
|
||||
b.HasOne("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("PaymentMethodId")
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.HasConstraintName("fk_order_payment_method_payment_method_id");
|
||||
|
||||
b.OwnsOne("HelloShop.OrderingService.Entities.Orders.Address", "Address", b1 =>
|
||||
{
|
||||
b1.Property<int>("OrderId")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id");
|
||||
|
||||
b1.Property<string>("City")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)")
|
||||
.HasColumnName("City");
|
||||
|
||||
b1.Property<string>("Country")
|
||||
.IsRequired()
|
||||
.HasMaxLength(8)
|
||||
.HasColumnType("character varying(8)")
|
||||
.HasColumnName("Country");
|
||||
|
||||
b1.Property<string>("State")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)")
|
||||
.HasColumnName("State");
|
||||
|
||||
b1.Property<string>("Street")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("Street");
|
||||
|
||||
b1.Property<string>("ZipCode")
|
||||
.IsRequired()
|
||||
.HasMaxLength(6)
|
||||
.HasColumnType("character varying(6)")
|
||||
.HasColumnName("ZipCode");
|
||||
|
||||
b1.HasKey("OrderId");
|
||||
|
||||
b1.ToTable("order");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("OrderId")
|
||||
.HasConstraintName("fk_order_order_id");
|
||||
});
|
||||
|
||||
b.Navigation("Address")
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b =>
|
||||
{
|
||||
b.HasOne("HelloShop.OrderingService.Entities.Orders.Order", null)
|
||||
.WithMany("OrderItems")
|
||||
.HasForeignKey("OrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired()
|
||||
.HasConstraintName("fk_order_item_order_order_id");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b =>
|
||||
{
|
||||
b.Navigation("PaymentMethods");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b =>
|
||||
{
|
||||
b.Navigation("OrderItems");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) HelloShop Corporation. All rights reserved.
|
||||
// See the license file in the project root for more information.
|
||||
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace HelloShop.OrderingService.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddEventLogTable : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "event_type_name",
|
||||
table: "distributed_event_log",
|
||||
type: "character varying(64)",
|
||||
maxLength: 64,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(32)",
|
||||
oldMaxLength: 32);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<string>(
|
||||
name: "event_type_name",
|
||||
table: "distributed_event_log",
|
||||
type: "character varying(32)",
|
||||
maxLength: 32,
|
||||
nullable: false,
|
||||
oldClrType: typeof(string),
|
||||
oldType: "character varying(64)",
|
||||
oldMaxLength: 64);
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
-41
@@ -22,6 +22,47 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HelloShop.EventBus.Logging.DistributedEventLog", b =>
|
||||
{
|
||||
b.Property<Guid>("EventId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("event_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreationTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("creation_time");
|
||||
|
||||
b.Property<string>("DistributedEvent")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("distributed_event");
|
||||
|
||||
b.Property<string>("EventTypeName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
.HasColumnName("event_type_name");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<int>("TimesSent")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("times_sent");
|
||||
|
||||
b.Property<Guid>("TransactionId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("transaction_id");
|
||||
|
||||
b.HasKey("EventId")
|
||||
.HasName("pk_distributed_event_log");
|
||||
|
||||
b.ToTable("distributed_event_log", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@@ -92,47 +133,6 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
|
||||
b.ToTable("payment_method", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.EventLogs.DistributedEventLog", b =>
|
||||
{
|
||||
b.Property<Guid>("EventId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("event_id");
|
||||
|
||||
b.Property<DateTimeOffset>("CreationTime")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("creation_time");
|
||||
|
||||
b.Property<string>("DistributedEvent")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("distributed_event");
|
||||
|
||||
b.Property<string>("EventTypeName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(32)
|
||||
.HasColumnType("character varying(32)")
|
||||
.HasColumnName("event_type_name");
|
||||
|
||||
b.Property<string>("Status")
|
||||
.IsRequired()
|
||||
.HasColumnType("text")
|
||||
.HasColumnName("status");
|
||||
|
||||
b.Property<int>("TimesSent")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("times_sent");
|
||||
|
||||
b.Property<Guid>("TransactionId")
|
||||
.HasColumnType("uuid")
|
||||
.HasColumnName("transaction_id");
|
||||
|
||||
b.HasKey("EventId")
|
||||
.HasName("pk_distributed_event_log");
|
||||
|
||||
b.ToTable("distributed_event_log", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Idempotency.ClientRequest", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) HelloShop Corporation. All rights reserved.
|
||||
// See the license file in the project root for more information.
|
||||
|
||||
using HelloShop.EventBus.Logging;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Reflection;
|
||||
|
||||
@@ -13,6 +14,7 @@ namespace HelloShop.OrderingService.Infrastructure
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
||||
builder.UseDistributedEventLogs();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user