using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Distribution.Migrations { /// public partial class AddProcurement : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "PurchaseOrders", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_SupplierId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_CreatedByUserId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), Status = table.Column(type: "int", nullable: false), CancelReason = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PurchaseOrders", x => x.Id); table.ForeignKey( name: "FK_PurchaseOrders_Suppliers_FK_SupplierId", column: x => x.FK_SupplierId, principalTable: "Suppliers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "GoodsReceipts", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_PurchaseOrderId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_ReceivedByUserId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_WarehouseId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), ReceivedAt = table.Column(type: "datetime(6)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_GoodsReceipts", x => x.Id); table.ForeignKey( name: "FK_GoodsReceipts_PurchaseOrders_FK_PurchaseOrderId", column: x => x.FK_PurchaseOrderId, principalTable: "PurchaseOrders", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_GoodsReceipts_Warehouses_FK_WarehouseId", column: x => x.FK_WarehouseId, principalTable: "Warehouses", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "PurchaseOrderItems", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_PurchaseOrderId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_ItemId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), Quantity = table.Column(type: "int", nullable: false), UnitCost = table.Column(type: "decimal(65,30)", nullable: false), ReceivedQuantity = table.Column(type: "int", nullable: false), CancelledQuantity = table.Column(type: "int", nullable: false), IsCancelled = table.Column(type: "tinyint(1)", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PurchaseOrderItems", x => x.Id); table.ForeignKey( name: "FK_PurchaseOrderItems_Items_FK_ItemId", column: x => x.FK_ItemId, principalTable: "Items", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_PurchaseOrderItems_PurchaseOrders_FK_PurchaseOrderId", column: x => x.FK_PurchaseOrderId, principalTable: "PurchaseOrders", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "PurchaseReturns", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_PurchaseOrderId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), Reason = table.Column(type: "longtext", nullable: false) .Annotation("MySql:CharSet", "utf8mb4"), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PurchaseReturns", x => x.Id); table.ForeignKey( name: "FK_PurchaseReturns_PurchaseOrders_FK_PurchaseOrderId", column: x => x.FK_PurchaseOrderId, principalTable: "PurchaseOrders", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "GoodsReceiptItems", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_GoodsReceiptId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_PurchaseOrderItemId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), AcceptedQuantity = table.Column(type: "int", nullable: false), RejectedQuantity = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_GoodsReceiptItems", x => x.Id); table.ForeignKey( name: "FK_GoodsReceiptItems_GoodsReceipts_FK_GoodsReceiptId", column: x => x.FK_GoodsReceiptId, principalTable: "GoodsReceipts", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_GoodsReceiptItems_PurchaseOrderItems_FK_PurchaseOrderItemId", column: x => x.FK_PurchaseOrderItemId, principalTable: "PurchaseOrderItems", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( name: "PurchaseReturnItems", columns: table => new { Id = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_PurchaseReturnId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), FK_ItemId = table.Column(type: "char(36)", nullable: false, collation: "ascii_general_ci"), Quantity = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime(6)", nullable: false), IsActive = table.Column(type: "tinyint(1)", nullable: false) }, constraints: table => { table.PrimaryKey("PK_PurchaseReturnItems", x => x.Id); table.ForeignKey( name: "FK_PurchaseReturnItems_Items_FK_ItemId", column: x => x.FK_ItemId, principalTable: "Items", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_PurchaseReturnItems_PurchaseReturns_FK_PurchaseReturnId", column: x => x.FK_PurchaseReturnId, principalTable: "PurchaseReturns", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }) .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateIndex( name: "IX_GoodsReceiptItems_FK_GoodsReceiptId", table: "GoodsReceiptItems", column: "FK_GoodsReceiptId"); migrationBuilder.CreateIndex( name: "IX_GoodsReceiptItems_FK_PurchaseOrderItemId", table: "GoodsReceiptItems", column: "FK_PurchaseOrderItemId"); migrationBuilder.CreateIndex( name: "IX_GoodsReceipts_FK_PurchaseOrderId", table: "GoodsReceipts", column: "FK_PurchaseOrderId"); migrationBuilder.CreateIndex( name: "IX_GoodsReceipts_FK_WarehouseId", table: "GoodsReceipts", column: "FK_WarehouseId"); migrationBuilder.CreateIndex( name: "IX_PurchaseOrderItems_FK_ItemId", table: "PurchaseOrderItems", column: "FK_ItemId"); migrationBuilder.CreateIndex( name: "IX_PurchaseOrderItems_FK_PurchaseOrderId", table: "PurchaseOrderItems", column: "FK_PurchaseOrderId"); migrationBuilder.CreateIndex( name: "IX_PurchaseOrders_FK_SupplierId", table: "PurchaseOrders", column: "FK_SupplierId"); migrationBuilder.CreateIndex( name: "IX_PurchaseReturnItems_FK_ItemId", table: "PurchaseReturnItems", column: "FK_ItemId"); migrationBuilder.CreateIndex( name: "IX_PurchaseReturnItems_FK_PurchaseReturnId", table: "PurchaseReturnItems", column: "FK_PurchaseReturnId"); migrationBuilder.CreateIndex( name: "IX_PurchaseReturns_FK_PurchaseOrderId", table: "PurchaseReturns", column: "FK_PurchaseOrderId"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "GoodsReceiptItems"); migrationBuilder.DropTable( name: "PurchaseReturnItems"); migrationBuilder.DropTable( name: "GoodsReceipts"); migrationBuilder.DropTable( name: "PurchaseOrderItems"); migrationBuilder.DropTable( name: "PurchaseReturns"); migrationBuilder.DropTable( name: "PurchaseOrders"); } } }