数据库对象命名约定

This commit is contained in:
administrator committed 2024-11-23 10:16:45 +08:00
1 parent 2036f447d5
commit a027f6fc04
41 files changed
+1136 -741

No files matched your search

@@ -8,5 +8,7 @@ namespace HelloShop.OrderingService.Constants
public const string MasterConnectionStringName = "OrderingDatabaseMaster";
public const string SlaveConnectionStringName = "OrderingDatabaseSlave";
public const string MigrationsHistoryTableName = "migrations_history";
}
}
@@ -36,7 +36,8 @@ namespace HelloShop.OrderingService.Extensions
builder.Services.AddDbContext<OrderingServiceDbContext>(options =>
{
options.UseNpgsql(builder.Configuration.GetConnectionString(DbConstants.MasterConnectionStringName));
options.UseNpgsql(builder.Configuration.GetConnectionString(DbConstants.MasterConnectionStringName), x => x.MigrationsHistoryTable(DbConstants.MigrationsHistoryTableName));
options.UseSnakeCaseNamingConvention();
});
builder.Services.AddScoped<IClientRequestManager, ClientRequestManager>();
@@ -8,6 +8,7 @@
<ProjectReference Include="..\HelloShop.ServiceDefaults\HelloShop.ServiceDefaults.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EFCore.NamingConventions" Version="8.0.3" />
<PackageReference Include="MediatR" Version="12.4.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
@@ -11,7 +11,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Buyers
{
public void Configure(EntityTypeBuilder<Buyer> builder)
{
builder.ToTable("Buyer");
builder.Property(x => x.Name).HasMaxLength(16).IsRequired();
builder.HasMany(b => b.PaymentMethods).WithOne().HasForeignKey(x => x.BuyerId).OnDelete(DeleteBehavior.Cascade);
}
@@ -11,8 +11,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Buyers
{
public void Configure(EntityTypeBuilder<PaymentMethod> builder)
{
builder.ToTable("PaymentMethods");
builder.Property(x => x.Alias).HasMaxLength(16);
builder.Property(x => x.CardNumber).HasMaxLength(16);
builder.Property(x => x.CardHolderName).HasMaxLength(16);
@@ -15,8 +15,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.EventLog
public void Configure(EntityTypeBuilder<DistributedEventLog> builder)
{
builder.ToTable("DistributedEventLogs");
builder.HasKey(x => x.EventId);
builder.Property(x => x.EventTypeName).HasMaxLength(32);
builder.Property(x => x.Status).HasConversion<string>();
@@ -11,8 +11,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Idempote
{
public void Configure(EntityTypeBuilder<ClientRequest> builder)
{
builder.ToTable("ClientRequests");
builder.HasKey(t => t.Id);
builder.Property(t => t.Name).HasMaxLength(64);
@@ -12,8 +12,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Orders
{
public void Configure(EntityTypeBuilder<Order> builder)
{
builder.ToTable("Orders");
builder.Property(x => x.Description).HasMaxLength(64);
builder.Property(x => x.OrderStatus).HasConversion<string>();
@@ -11,8 +11,6 @@ namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Orders
{
public void Configure(EntityTypeBuilder<OrderItem> builder)
{
builder.ToTable("OrderItems");
builder.Property(x => x.ProductName).HasMaxLength(16);
builder.Property(x => x.PictureUrl).HasMaxLength(256);
}
@@ -1,149 +0,0 @@
// Copyright (c) HelloShop Corporation. All rights reserved.
// See the license file in the project root for more information.
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace HelloShop.OrderingService.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Buyer",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Buyer", x => x.Id);
});
migrationBuilder.CreateTable(
name: "PaymentMethods",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
BuyerId = table.Column<int>(type: "integer", nullable: false),
Alias = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
CardNumber = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
CardHolderName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
SecurityNumber = table.Column<string>(type: "character varying(6)", maxLength: 6, nullable: true),
Expiration = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PaymentMethods", x => x.Id);
table.ForeignKey(
name: "FK_PaymentMethods_Buyer_BuyerId",
column: x => x.BuyerId,
principalTable: "Buyer",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OrderDate = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Country = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: false),
State = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
City = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
Street = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
ZipCode = table.Column<string>(type: "character varying(6)", maxLength: 6, nullable: false),
OrderStatus = table.Column<string>(type: "text", nullable: false),
BuyerId = table.Column<int>(type: "integer", nullable: false),
PaymentMethodId = table.Column<int>(type: "integer", nullable: true),
Description = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Buyer_BuyerId",
column: x => x.BuyerId,
principalTable: "Buyer",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_PaymentMethods_PaymentMethodId",
column: x => x.PaymentMethodId,
principalTable: "PaymentMethods",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "OrderItems",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OrderId = table.Column<int>(type: "integer", nullable: false),
ProductId = table.Column<int>(type: "integer", nullable: false),
ProductName = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
PictureUrl = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
UnitPrice = table.Column<decimal>(type: "numeric", nullable: false),
Units = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_OrderItems", x => x.Id);
table.ForeignKey(
name: "FK_OrderItems_Orders_OrderId",
column: x => x.OrderId,
principalTable: "Orders",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_OrderItems_OrderId",
table: "OrderItems",
column: "OrderId");
migrationBuilder.CreateIndex(
name: "IX_Orders_BuyerId",
table: "Orders",
column: "BuyerId");
migrationBuilder.CreateIndex(
name: "IX_Orders_PaymentMethodId",
table: "Orders",
column: "PaymentMethodId");
migrationBuilder.CreateIndex(
name: "IX_PaymentMethods_BuyerId",
table: "PaymentMethods",
column: "BuyerId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "OrderItems");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "PaymentMethods");
migrationBuilder.DropTable(
name: "Buyer");
}
}
}
@@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace HelloShop.OrderingService.Infrastructure.Migrations
{
[DbContext(typeof(OrderingServiceDbContext))]
[Migration("20240829142135_InitialCreate")]
[Migration("20241123020913_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@@ -20,7 +20,7 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@@ -29,129 +29,223 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)");
.HasColumnType("character varying(16)")
.HasColumnName("name");
b.HasKey("Id");
b.HasKey("Id")
.HasName("pk_buyer");
b.ToTable("Buyer", (string)null);
b.ToTable("buyer", (string)null);
});
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Alias")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)");
.HasColumnType("character varying(16)")
.HasColumnName("alias");
b.Property<int>("BuyerId")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("buyer_id");
b.Property<string>("CardHolderName")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)");
.HasColumnType("character varying(16)")
.HasColumnName("card_holder_name");
b.Property<string>("CardNumber")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)");
.HasColumnType("character varying(16)")
.HasColumnName("card_number");
b.Property<DateTimeOffset?>("Expiration")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp with time zone")
.HasColumnName("expiration");
b.Property<string>("SecurityNumber")
.HasMaxLength(6)
.HasColumnType("character varying(6)");
.HasColumnType("character varying(6)")
.HasColumnName("security_number");
b.HasKey("Id");
b.HasKey("Id")
.HasName("pk_payment_method");
b.HasIndex("BuyerId");
b.HasIndex("BuyerId")
.HasDatabaseName("ix_payment_method_buyer_id");
b.ToTable("PaymentMethods", (string)null);
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")
.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");
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("BuyerId")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("buyer_id");
b.Property<string>("Description")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
.HasColumnType("character varying(64)")
.HasColumnName("description");
b.Property<DateTimeOffset>("OrderDate")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp with time zone")
.HasColumnName("order_date");
b.Property<string>("OrderStatus")
.IsRequired()
.HasColumnType("text");
.HasColumnType("text")
.HasColumnName("order_status");
b.Property<int?>("PaymentMethodId")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("payment_method_id");
b.HasKey("Id");
b.HasKey("Id")
.HasName("pk_order");
b.HasIndex("BuyerId");
b.HasIndex("BuyerId")
.HasDatabaseName("ix_order_buyer_id");
b.HasIndex("PaymentMethodId");
b.HasIndex("PaymentMethodId")
.HasDatabaseName("ix_order_payment_method_id");
b.ToTable("Orders", (string)null);
b.ToTable("order", (string)null);
});
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("OrderId")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("order_id");
b.Property<string>("PictureUrl")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)");
.HasColumnType("character varying(256)")
.HasColumnName("picture_url");
b.Property<int>("ProductId")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("product_id");
b.Property<string>("ProductName")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)");
.HasColumnType("character varying(16)")
.HasColumnName("product_name");
b.Property<decimal>("UnitPrice")
.HasColumnType("numeric");
.HasColumnType("numeric")
.HasColumnName("unit_price");
b.Property<int>("Units")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("units");
b.HasKey("Id");
b.HasKey("Id")
.HasName("pk_order_item");
b.HasIndex("OrderId");
b.HasIndex("OrderId")
.HasDatabaseName("ix_order_item_order_id");
b.ToTable("OrderItems", (string)null);
b.ToTable("order_item", (string)null);
});
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b =>
@@ -160,7 +254,8 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
.WithMany("PaymentMethods")
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.IsRequired()
.HasConstraintName("fk_payment_method_buyer_buyer_id");
});
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b =>
@@ -169,17 +264,20 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
.WithMany()
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.IsRequired()
.HasConstraintName("fk_order_buyer_buyer_id");
b.HasOne("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", null)
.WithMany()
.HasForeignKey("PaymentMethodId")
.OnDelete(DeleteBehavior.Restrict);
.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");
.HasColumnType("integer")
.HasColumnName("id");
b1.Property<string>("City")
.IsRequired()
@@ -213,10 +311,11 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
b1.HasKey("OrderId");
b1.ToTable("Orders");
b1.ToTable("order");
b1.WithOwner()
.HasForeignKey("OrderId");
.HasForeignKey("OrderId")
.HasConstraintName("fk_order_order_id");
});
b.Navigation("Address")
@@ -229,7 +328,8 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
.WithMany("OrderItems")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.IsRequired()
.HasConstraintName("fk_order_item_order_order_id");
});
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b =>
@@ -0,0 +1,183 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace HelloShop.OrderingService.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "buyer",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
name = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_buyer", x => x.id);
});
migrationBuilder.CreateTable(
name: "client_request",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
name = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: false),
time = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_client_request", x => x.id);
});
migrationBuilder.CreateTable(
name: "distributed_event_log",
columns: table => new
{
event_id = table.Column<Guid>(type: "uuid", nullable: false),
event_type_name = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
distributed_event = table.Column<string>(type: "text", nullable: false),
status = table.Column<string>(type: "text", nullable: false),
times_sent = table.Column<int>(type: "integer", nullable: false),
creation_time = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
transaction_id = table.Column<Guid>(type: "uuid", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_distributed_event_log", x => x.event_id);
});
migrationBuilder.CreateTable(
name: "payment_method",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
buyer_id = table.Column<int>(type: "integer", nullable: false),
alias = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
card_number = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
card_holder_name = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
security_number = table.Column<string>(type: "character varying(6)", maxLength: 6, nullable: true),
expiration = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_payment_method", x => x.id);
table.ForeignKey(
name: "fk_payment_method_buyer_buyer_id",
column: x => x.buyer_id,
principalTable: "buyer",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "order",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
order_date = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Country = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: false),
State = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
City = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
Street = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
ZipCode = table.Column<string>(type: "character varying(6)", maxLength: 6, nullable: false),
order_status = table.Column<string>(type: "text", nullable: false),
buyer_id = table.Column<int>(type: "integer", nullable: false),
payment_method_id = table.Column<int>(type: "integer", nullable: true),
description = table.Column<string>(type: "character varying(64)", maxLength: 64, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_order", x => x.id);
table.ForeignKey(
name: "fk_order_buyer_buyer_id",
column: x => x.buyer_id,
principalTable: "buyer",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_order_payment_method_payment_method_id",
column: x => x.payment_method_id,
principalTable: "payment_method",
principalColumn: "id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "order_item",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
order_id = table.Column<int>(type: "integer", nullable: false),
product_id = table.Column<int>(type: "integer", nullable: false),
product_name = table.Column<string>(type: "character varying(16)", maxLength: 16, nullable: false),
picture_url = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
unit_price = table.Column<decimal>(type: "numeric", nullable: false),
units = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_order_item", x => x.id);
table.ForeignKey(
name: "fk_order_item_order_order_id",
column: x => x.order_id,
principalTable: "order",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_order_buyer_id",
table: "order",
column: "buyer_id");
migrationBuilder.CreateIndex(
name: "ix_order_payment_method_id",
table: "order",
column: "payment_method_id");
migrationBuilder.CreateIndex(
name: "ix_order_item_order_id",
table: "order_item",
column: "order_id");
migrationBuilder.CreateIndex(
name: "ix_payment_method_buyer_id",
table: "payment_method",
column: "buyer_id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "client_request");
migrationBuilder.DropTable(
name: "distributed_event_log");
migrationBuilder.DropTable(
name: "order_item");
migrationBuilder.DropTable(
name: "order");
migrationBuilder.DropTable(
name: "payment_method");
migrationBuilder.DropTable(
name: "buyer");
}
}
}
@@ -17,7 +17,7 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.8")
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@@ -26,129 +26,223 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)");
.HasColumnType("character varying(16)")
.HasColumnName("name");
b.HasKey("Id");
b.HasKey("Id")
.HasName("pk_buyer");
b.ToTable("Buyer", (string)null);
b.ToTable("buyer", (string)null);
});
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Alias")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)");
.HasColumnType("character varying(16)")
.HasColumnName("alias");
b.Property<int>("BuyerId")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("buyer_id");
b.Property<string>("CardHolderName")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)");
.HasColumnType("character varying(16)")
.HasColumnName("card_holder_name");
b.Property<string>("CardNumber")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)");
.HasColumnType("character varying(16)")
.HasColumnName("card_number");
b.Property<DateTimeOffset?>("Expiration")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp with time zone")
.HasColumnName("expiration");
b.Property<string>("SecurityNumber")
.HasMaxLength(6)
.HasColumnType("character varying(6)");
.HasColumnType("character varying(6)")
.HasColumnName("security_number");
b.HasKey("Id");
b.HasKey("Id")
.HasName("pk_payment_method");
b.HasIndex("BuyerId");
b.HasIndex("BuyerId")
.HasDatabaseName("ix_payment_method_buyer_id");
b.ToTable("PaymentMethods", (string)null);
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")
.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");
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("BuyerId")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("buyer_id");
b.Property<string>("Description")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
.HasColumnType("character varying(64)")
.HasColumnName("description");
b.Property<DateTimeOffset>("OrderDate")
.HasColumnType("timestamp with time zone");
.HasColumnType("timestamp with time zone")
.HasColumnName("order_date");
b.Property<string>("OrderStatus")
.IsRequired()
.HasColumnType("text");
.HasColumnType("text")
.HasColumnName("order_status");
b.Property<int?>("PaymentMethodId")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("payment_method_id");
b.HasKey("Id");
b.HasKey("Id")
.HasName("pk_order");
b.HasIndex("BuyerId");
b.HasIndex("BuyerId")
.HasDatabaseName("ix_order_buyer_id");
b.HasIndex("PaymentMethodId");
b.HasIndex("PaymentMethodId")
.HasDatabaseName("ix_order_payment_method_id");
b.ToTable("Orders", (string)null);
b.ToTable("order", (string)null);
});
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("OrderId")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("order_id");
b.Property<string>("PictureUrl")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)");
.HasColumnType("character varying(256)")
.HasColumnName("picture_url");
b.Property<int>("ProductId")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("product_id");
b.Property<string>("ProductName")
.IsRequired()
.HasMaxLength(16)
.HasColumnType("character varying(16)");
.HasColumnType("character varying(16)")
.HasColumnName("product_name");
b.Property<decimal>("UnitPrice")
.HasColumnType("numeric");
.HasColumnType("numeric")
.HasColumnName("unit_price");
b.Property<int>("Units")
.HasColumnType("integer");
.HasColumnType("integer")
.HasColumnName("units");
b.HasKey("Id");
b.HasKey("Id")
.HasName("pk_order_item");
b.HasIndex("OrderId");
b.HasIndex("OrderId")
.HasDatabaseName("ix_order_item_order_id");
b.ToTable("OrderItems", (string)null);
b.ToTable("order_item", (string)null);
});
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b =>
@@ -157,7 +251,8 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
.WithMany("PaymentMethods")
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.IsRequired()
.HasConstraintName("fk_payment_method_buyer_buyer_id");
});
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b =>
@@ -166,17 +261,20 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
.WithMany()
.HasForeignKey("BuyerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.IsRequired()
.HasConstraintName("fk_order_buyer_buyer_id");
b.HasOne("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", null)
.WithMany()
.HasForeignKey("PaymentMethodId")
.OnDelete(DeleteBehavior.Restrict);
.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");
.HasColumnType("integer")
.HasColumnName("id");
b1.Property<string>("City")
.IsRequired()
@@ -210,10 +308,11 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
b1.HasKey("OrderId");
b1.ToTable("Orders");
b1.ToTable("order");
b1.WithOwner()
.HasForeignKey("OrderId");
.HasForeignKey("OrderId")
.HasConstraintName("fk_order_order_id");
});
b.Navigation("Address")
@@ -226,7 +325,8 @@ namespace HelloShop.OrderingService.Infrastructure.Migrations
.WithMany("OrderItems")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.IsRequired()
.HasConstraintName("fk_order_item_order_order_id");
});
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b =>
@@ -7,7 +7,7 @@
},
"AllowedHosts": "*",
"ConnectionStrings": {
"OrderingDatabaseMaster": "Host=localhost;Port=5432;Database=OrderingService;Username=postgres;Password=postgres",
"OrderingDatabaseSlave": "Host=localhost;Port=5432;Database=OrderingService;Username=postgres;Password=postgres"
"OrderingDatabaseMaster": "Host=localhost;Port=5432;Database=ordering;Username=postgres;Password=postgres",
"OrderingDatabaseSlave": "Host=localhost;Port=5432;Database=ordering;Username=postgres;Password=postgres"
}
}