using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace CutList.Web.Migrations { /// public partial class RemoveVendorData : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.DropForeignKey( name: "FK_StockTransactions_Suppliers_SupplierId", table: "StockTransactions"); migrationBuilder.DropTable( name: "PurchaseItems"); migrationBuilder.DropTable( name: "SupplierOfferings"); migrationBuilder.DropTable( name: "Suppliers"); migrationBuilder.DropIndex( name: "IX_StockTransactions_SupplierId", table: "StockTransactions"); migrationBuilder.DropColumn( name: "SupplierId", table: "StockTransactions"); migrationBuilder.DropColumn( name: "UnitPrice", table: "StockTransactions"); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "SupplierId", table: "StockTransactions", type: "int", nullable: true); migrationBuilder.AddColumn( name: "UnitPrice", table: "StockTransactions", type: "decimal(10,2)", precision: 10, scale: 2, nullable: true); migrationBuilder.CreateTable( name: "Suppliers", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ContactInfo = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true), CreatedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"), IsActive = table.Column(type: "bit", nullable: false), Name = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: false), Notes = table.Column(type: "nvarchar(max)", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Suppliers", x => x.Id); }); migrationBuilder.CreateTable( name: "PurchaseItems", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), JobId = table.Column(type: "int", nullable: true), StockItemId = table.Column(type: "int", nullable: false), SupplierId = table.Column(type: "int", nullable: true), CreatedAt = table.Column(type: "datetime2", nullable: false, defaultValueSql: "GETUTCDATE()"), Notes = table.Column(type: "nvarchar(500)", maxLength: 500, nullable: true), Quantity = table.Column(type: "int", nullable: false), Status = table.Column(type: "nvarchar(20)", maxLength: 20, nullable: false), UpdatedAt = table.Column(type: "datetime2", nullable: true) }, constraints: table => { table.PrimaryKey("PK_PurchaseItems", x => x.Id); table.ForeignKey( name: "FK_PurchaseItems_Jobs_JobId", column: x => x.JobId, principalTable: "Jobs", principalColumn: "Id", onDelete: ReferentialAction.SetNull); table.ForeignKey( name: "FK_PurchaseItems_StockItems_StockItemId", column: x => x.StockItemId, principalTable: "StockItems", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_PurchaseItems_Suppliers_SupplierId", column: x => x.SupplierId, principalTable: "Suppliers", principalColumn: "Id", onDelete: ReferentialAction.SetNull); }); migrationBuilder.CreateTable( name: "SupplierOfferings", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), StockItemId = table.Column(type: "int", nullable: false), SupplierId = table.Column(type: "int", nullable: false), IsActive = table.Column(type: "bit", nullable: false), Notes = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true), PartNumber = table.Column(type: "nvarchar(100)", maxLength: 100, nullable: true), Price = table.Column(type: "decimal(10,2)", precision: 10, scale: 2, nullable: true), SupplierDescription = table.Column(type: "nvarchar(255)", maxLength: 255, nullable: true) }, constraints: table => { table.PrimaryKey("PK_SupplierOfferings", x => x.Id); table.ForeignKey( name: "FK_SupplierOfferings_StockItems_StockItemId", column: x => x.StockItemId, principalTable: "StockItems", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_SupplierOfferings_Suppliers_SupplierId", column: x => x.SupplierId, principalTable: "Suppliers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_StockTransactions_SupplierId", table: "StockTransactions", column: "SupplierId"); migrationBuilder.CreateIndex( name: "IX_PurchaseItems_JobId", table: "PurchaseItems", column: "JobId"); migrationBuilder.CreateIndex( name: "IX_PurchaseItems_StockItemId", table: "PurchaseItems", column: "StockItemId"); migrationBuilder.CreateIndex( name: "IX_PurchaseItems_SupplierId", table: "PurchaseItems", column: "SupplierId"); migrationBuilder.CreateIndex( name: "IX_SupplierOfferings_StockItemId", table: "SupplierOfferings", column: "StockItemId"); migrationBuilder.CreateIndex( name: "IX_SupplierOfferings_SupplierId_StockItemId", table: "SupplierOfferings", columns: new[] { "SupplierId", "StockItemId" }, unique: true); migrationBuilder.AddForeignKey( name: "FK_StockTransactions_Suppliers_SupplierId", table: "StockTransactions", column: "SupplierId", principalTable: "Suppliers", principalColumn: "Id", onDelete: ReferentialAction.SetNull); } } }