using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace PowderCoating.Infrastructure.Migrations { /// public partial class AddPurchaseOrders : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Appointments_AspNetUsers_AssignedUserId", table: "Appointments"); migrationBuilder.DropForeignKey( name: "FK_Jobs_AspNetUsers_AssignedUserId", table: "Jobs"); migrationBuilder.DropForeignKey( name: "FK_MaintenanceRecords_AspNetUsers_AssignedUserId", table: "MaintenanceRecords"); migrationBuilder.AddColumn( name: "PurchaseOrderId", table: "InventoryTransactions", type: "int", nullable: true); migrationBuilder.CreateTable( name: "PurchaseOrders", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), PoNumber = table.Column(type: "nvarchar(max)", nullable: false), VendorId = table.Column(type: "int", nullable: false), Status = table.Column(type: "int", nullable: false), OrderDate = table.Column(type: "datetime2", nullable: false), ExpectedDeliveryDate = table.Column(type: "datetime2", nullable: true), ReceivedDate = table.Column(type: "datetime2", nullable: true), ShippingCost = table.Column(type: "decimal(18,2)", nullable: false), SubTotal = table.Column(type: "decimal(18,2)", nullable: false), TotalAmount = table.Column(type: "decimal(18,2)", nullable: false), Notes = table.Column(type: "nvarchar(max)", nullable: true), InternalNotes = table.Column(type: "nvarchar(max)", nullable: true), BillId = table.Column(type: "int", nullable: true), CompanyId = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), UpdatedAt = table.Column(type: "datetime2", nullable: true), CreatedBy = table.Column(type: "nvarchar(max)", nullable: true), UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false), DeletedAt = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_PurchaseOrders", x => x.Id); table.ForeignKey( name: "FK_PurchaseOrders_Bills_BillId", column: x => x.BillId, principalTable: "Bills", principalColumn: "Id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "FK_PurchaseOrders_Vendors_VendorId", column: x => x.VendorId, principalTable: "Vendors", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "PurchaseOrderItems", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), PurchaseOrderId = table.Column(type: "int", nullable: false), InventoryItemId = table.Column(type: "int", nullable: false), QuantityOrdered = table.Column(type: "decimal(18,2)", nullable: false), QuantityReceived = table.Column(type: "decimal(18,2)", nullable: false), UnitCost = table.Column(type: "decimal(18,2)", nullable: false), LineTotal = table.Column(type: "decimal(18,2)", nullable: false), Notes = table.Column(type: "nvarchar(max)", nullable: true), CompanyId = table.Column(type: "int", nullable: false), CreatedAt = table.Column(type: "datetime2", nullable: false), UpdatedAt = table.Column(type: "datetime2", nullable: true), CreatedBy = table.Column(type: "nvarchar(max)", nullable: true), UpdatedBy = table.Column(type: "nvarchar(max)", nullable: true), IsDeleted = table.Column(type: "bit", nullable: false), DeletedAt = table.Column(type: "datetime2", nullable: true), DeletedBy = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_PurchaseOrderItems", x => x.Id); table.ForeignKey( name: "FK_PurchaseOrderItems_InventoryItems_InventoryItemId", column: x => x.InventoryItemId, principalTable: "InventoryItems", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "FK_PurchaseOrderItems_PurchaseOrders_PurchaseOrderId", column: x => x.PurchaseOrderId, principalTable: "PurchaseOrders", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 1, column: "CreatedAt", value: new DateTime(2026, 3, 14, 14, 0, 17, 340, DateTimeKind.Utc).AddTicks(3350)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 2, column: "CreatedAt", value: new DateTime(2026, 3, 14, 14, 0, 17, 340, DateTimeKind.Utc).AddTicks(3360)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 3, column: "CreatedAt", value: new DateTime(2026, 3, 14, 14, 0, 17, 340, DateTimeKind.Utc).AddTicks(3362)); migrationBuilder.CreateIndex( name: "IX_InventoryTransactions_PurchaseOrderId", table: "InventoryTransactions", column: "PurchaseOrderId"); migrationBuilder.CreateIndex( name: "IX_PurchaseOrderItems_InventoryItemId", table: "PurchaseOrderItems", column: "InventoryItemId"); migrationBuilder.CreateIndex( name: "IX_PurchaseOrderItems_PurchaseOrderId", table: "PurchaseOrderItems", column: "PurchaseOrderId"); migrationBuilder.CreateIndex( name: "IX_PurchaseOrders_BillId", table: "PurchaseOrders", column: "BillId"); migrationBuilder.CreateIndex( name: "IX_PurchaseOrders_VendorId", table: "PurchaseOrders", column: "VendorId"); migrationBuilder.AddForeignKey( name: "FK_Appointments_AspNetUsers_AssignedUserId", table: "Appointments", column: "AssignedUserId", principalTable: "AspNetUsers", principalColumn: "Id"); migrationBuilder.AddForeignKey( name: "FK_InventoryTransactions_PurchaseOrders_PurchaseOrderId", table: "InventoryTransactions", column: "PurchaseOrderId", principalTable: "PurchaseOrders", principalColumn: "Id"); migrationBuilder.AddForeignKey( name: "FK_Jobs_AspNetUsers_AssignedUserId", table: "Jobs", column: "AssignedUserId", principalTable: "AspNetUsers", principalColumn: "Id"); migrationBuilder.AddForeignKey( name: "FK_MaintenanceRecords_AspNetUsers_AssignedUserId", table: "MaintenanceRecords", column: "AssignedUserId", principalTable: "AspNetUsers", principalColumn: "Id"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_Appointments_AspNetUsers_AssignedUserId", table: "Appointments"); migrationBuilder.DropForeignKey( name: "FK_InventoryTransactions_PurchaseOrders_PurchaseOrderId", table: "InventoryTransactions"); migrationBuilder.DropForeignKey( name: "FK_Jobs_AspNetUsers_AssignedUserId", table: "Jobs"); migrationBuilder.DropForeignKey( name: "FK_MaintenanceRecords_AspNetUsers_AssignedUserId", table: "MaintenanceRecords"); migrationBuilder.DropTable( name: "PurchaseOrderItems"); migrationBuilder.DropTable( name: "PurchaseOrders"); migrationBuilder.DropIndex( name: "IX_InventoryTransactions_PurchaseOrderId", table: "InventoryTransactions"); migrationBuilder.DropColumn( name: "PurchaseOrderId", table: "InventoryTransactions"); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 1, column: "CreatedAt", value: new DateTime(2026, 3, 13, 20, 31, 2, 381, DateTimeKind.Utc).AddTicks(3596)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 2, column: "CreatedAt", value: new DateTime(2026, 3, 13, 20, 31, 2, 381, DateTimeKind.Utc).AddTicks(3602)); migrationBuilder.UpdateData( table: "PricingTiers", keyColumn: "Id", keyValue: 3, column: "CreatedAt", value: new DateTime(2026, 3, 13, 20, 31, 2, 381, DateTimeKind.Utc).AddTicks(3603)); migrationBuilder.AddForeignKey( name: "FK_Appointments_AspNetUsers_AssignedUserId", table: "Appointments", column: "AssignedUserId", principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.SetNull); migrationBuilder.AddForeignKey( name: "FK_Jobs_AspNetUsers_AssignedUserId", table: "Jobs", column: "AssignedUserId", principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.SetNull); migrationBuilder.AddForeignKey( name: "FK_MaintenanceRecords_AspNetUsers_AssignedUserId", table: "MaintenanceRecords", column: "AssignedUserId", principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.SetNull); } } }