订单微服务实体实现
This commit is contained in:
1 parent
b0b9491dfe
commit
2201f36422
69 files changed
+1042
-67
No files matched your search
+19
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) HelloShop Corporation. All rights reserved.
|
||||
// See the license file in the project root for more information.
|
||||
|
||||
using HelloShop.OrderingService.Entities.Buyers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Buyers
|
||||
{
|
||||
public class BuyerEntityTypeConfiguration : IEntityTypeConfiguration<Buyer>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) HelloShop Corporation. All rights reserved.
|
||||
// See the license file in the project root for more information.
|
||||
|
||||
using HelloShop.OrderingService.Entities.Buyers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Buyers
|
||||
{
|
||||
public class PaymentMethodEntityTypeConfiguration : IEntityTypeConfiguration<PaymentMethod>
|
||||
{
|
||||
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);
|
||||
builder.Property(x => x.SecurityNumber).HasMaxLength(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) HelloShop Corporation. All rights reserved.
|
||||
// See the license file in the project root for more information.
|
||||
|
||||
using HelloShop.OrderingService.Entities.Buyers;
|
||||
using HelloShop.OrderingService.Entities.Orders;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Orders
|
||||
{
|
||||
public class OrderEntityTypeConfiguration : IEntityTypeConfiguration<Order>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Order> builder)
|
||||
{
|
||||
builder.ToTable("Orders");
|
||||
|
||||
builder.Property(x => x.Description).HasMaxLength(64);
|
||||
builder.Property(x => x.OrderStatus).HasConversion<string>();
|
||||
|
||||
builder.OwnsOne(x => x.Address, ownedAddress =>
|
||||
{
|
||||
ownedAddress.Property(x => x.Country).HasColumnName(nameof(Address.Country)).HasMaxLength(8).IsRequired();
|
||||
ownedAddress.Property(x => x.State).HasColumnName(nameof(Address.State)).HasMaxLength(16).IsRequired();
|
||||
ownedAddress.Property(x => x.City).HasColumnName(nameof(Address.City)).HasMaxLength(16).IsRequired();
|
||||
ownedAddress.Property(x => x.Street).HasColumnName(nameof(Address.Street)).HasMaxLength(32).IsRequired();
|
||||
ownedAddress.Property(x => x.ZipCode).HasColumnName(nameof(Address.ZipCode)).HasMaxLength(6).IsRequired();
|
||||
});
|
||||
|
||||
builder.HasOne<Buyer>().WithMany().HasForeignKey(x => x.BuyerId).OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasMany(x => x.OrderItems).WithOne().HasForeignKey(x => x.OrderId).OnDelete(DeleteBehavior.Cascade);
|
||||
builder.HasOne<PaymentMethod>().WithMany().HasForeignKey(x => x.PaymentMethodId).OnDelete(DeleteBehavior.Restrict);
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) HelloShop Corporation. All rights reserved.
|
||||
// See the license file in the project root for more information.
|
||||
|
||||
using HelloShop.OrderingService.Entities.Orders;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace HelloShop.OrderingService.Infrastructure.EntityConfigurations.Orders
|
||||
{
|
||||
public class OrderItemEntityTypeConfiguration : IEntityTypeConfiguration<OrderItem>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<OrderItem> builder)
|
||||
{
|
||||
builder.ToTable("OrderItems");
|
||||
|
||||
builder.Property(x => x.ProductName).HasMaxLength(16);
|
||||
builder.Property(x => x.PictureUrl).HasMaxLength(256);
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
+247
@@ -0,0 +1,247 @@
|
||||
// <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("20240829142135_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.8")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Buyer", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Alias")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.Property<int>("BuyerId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("CardHolderName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.Property<string>("CardNumber")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.Property<DateTimeOffset?>("Expiration")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("SecurityNumber")
|
||||
.HasMaxLength(6)
|
||||
.HasColumnType("character varying(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuyerId");
|
||||
|
||||
b.ToTable("PaymentMethods", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuyerId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<DateTimeOffset>("OrderDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("OrderStatus")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("PaymentMethodId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuyerId");
|
||||
|
||||
b.HasIndex("PaymentMethodId");
|
||||
|
||||
b.ToTable("Orders", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("PictureUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.Property<decimal>("UnitPrice")
|
||||
.HasColumnType("numeric");
|
||||
|
||||
b.Property<int>("Units")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.ToTable("OrderItems", (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();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b =>
|
||||
{
|
||||
b.HasOne("HelloShop.OrderingService.Entities.Buyers.Buyer", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("BuyerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("PaymentMethodId")
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.OwnsOne("HelloShop.OrderingService.Entities.Orders.Address", "Address", b1 =>
|
||||
{
|
||||
b1.Property<int>("OrderId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
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("Orders");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("OrderId");
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using HelloShop.OrderingService.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace HelloShop.OrderingService.Infrastructure.Migrations
|
||||
{
|
||||
[DbContext(typeof(OrderingServiceDbContext))]
|
||||
partial class OrderingServiceDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.8")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.Buyer", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Buyer", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Alias")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.Property<int>("BuyerId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("CardHolderName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.Property<string>("CardNumber")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.Property<DateTimeOffset?>("Expiration")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("SecurityNumber")
|
||||
.HasMaxLength(6)
|
||||
.HasColumnType("character varying(6)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuyerId");
|
||||
|
||||
b.ToTable("PaymentMethods", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("BuyerId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)");
|
||||
|
||||
b.Property<DateTimeOffset>("OrderDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("OrderStatus")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int?>("PaymentMethodId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("BuyerId");
|
||||
|
||||
b.HasIndex("PaymentMethodId");
|
||||
|
||||
b.ToTable("Orders", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.OrderItem", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("PictureUrl")
|
||||
.IsRequired()
|
||||
.HasMaxLength(256)
|
||||
.HasColumnType("character varying(256)");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductName")
|
||||
.IsRequired()
|
||||
.HasMaxLength(16)
|
||||
.HasColumnType("character varying(16)");
|
||||
|
||||
b.Property<decimal>("UnitPrice")
|
||||
.HasColumnType("numeric");
|
||||
|
||||
b.Property<int>("Units")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.ToTable("OrderItems", (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();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("HelloShop.OrderingService.Entities.Orders.Order", b =>
|
||||
{
|
||||
b.HasOne("HelloShop.OrderingService.Entities.Buyers.Buyer", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("BuyerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("HelloShop.OrderingService.Entities.Buyers.PaymentMethod", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("PaymentMethodId")
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
b.OwnsOne("HelloShop.OrderingService.Entities.Orders.Address", "Address", b1 =>
|
||||
{
|
||||
b1.Property<int>("OrderId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
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("Orders");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("OrderId");
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) HelloShop Corporation. All rights reserved.
|
||||
// See the license file in the project root for more information.
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Reflection;
|
||||
|
||||
namespace HelloShop.OrderingService.Infrastructure
|
||||
{
|
||||
public partial class OrderingServiceDbContext(DbContextOptions<OrderingServiceDbContext> options) : DbContext(options)
|
||||
{
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
```shell
|
||||
dotnet ef database drop --force
|
||||
dotnet ef migrations remove
|
||||
dotnet ef migrations add InitialCreate --output-dir Infrastructure/Migrations
|
||||
dotnet ef database update
|
||||
```
|
||||
Reference in new issue
Block a user