feat: remove Supplier/SupplierOffering/PurchaseItem entities and migrate schema

This commit is contained in:
aj
2026-08-01 08:49:05 -04:00
parent 41944638c6
commit 1b4d5f76a8
9 changed files with 868 additions and 318 deletions
-68
View File
@@ -12,15 +12,12 @@ public class ApplicationDbContext : DbContext
public DbSet<Material> Materials => Set<Material>();
public DbSet<MaterialDimensions> MaterialDimensions => Set<MaterialDimensions>();
public DbSet<Supplier> Suppliers => Set<Supplier>();
public DbSet<StockItem> StockItems => Set<StockItem>();
public DbSet<SupplierOffering> SupplierOfferings => Set<SupplierOffering>();
public DbSet<StockTransaction> StockTransactions => Set<StockTransaction>();
public DbSet<CuttingTool> CuttingTools => Set<CuttingTool>();
public DbSet<Job> Jobs => Set<Job>();
public DbSet<JobPart> JobParts => Set<JobPart>();
public DbSet<JobStock> JobStocks => Set<JobStock>();
public DbSet<PurchaseItem> PurchaseItems => Set<PurchaseItem>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -143,15 +140,6 @@ public class ApplicationDbContext : DbContext
entity.HasIndex(e => e.NominalSize);
});
// Supplier
modelBuilder.Entity<Supplier>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Name).HasMaxLength(100).IsRequired();
entity.Property(e => e.ContactInfo).HasMaxLength(500);
entity.Property(e => e.CreatedAt).HasDefaultValueSql("GETUTCDATE()");
});
// StockItem
modelBuilder.Entity<StockItem>(entity =>
{
@@ -174,7 +162,6 @@ public class ApplicationDbContext : DbContext
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Notes).HasMaxLength(500);
entity.Property(e => e.UnitPrice).HasPrecision(10, 2);
entity.Property(e => e.CreatedAt).HasDefaultValueSql("GETUTCDATE()");
entity.HasOne(e => e.StockItem)
@@ -186,33 +173,6 @@ public class ApplicationDbContext : DbContext
.WithMany()
.HasForeignKey(e => e.JobId)
.OnDelete(DeleteBehavior.SetNull);
entity.HasOne(e => e.Supplier)
.WithMany()
.HasForeignKey(e => e.SupplierId)
.OnDelete(DeleteBehavior.SetNull);
});
// SupplierOffering
modelBuilder.Entity<SupplierOffering>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.PartNumber).HasMaxLength(100);
entity.Property(e => e.SupplierDescription).HasMaxLength(255);
entity.Property(e => e.Price).HasPrecision(10, 2);
entity.Property(e => e.Notes).HasMaxLength(255);
entity.HasOne(e => e.StockItem)
.WithMany(s => s.SupplierOfferings)
.HasForeignKey(e => e.StockItemId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(e => e.Supplier)
.WithMany(s => s.Offerings)
.HasForeignKey(e => e.SupplierId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasIndex(e => new { e.SupplierId, e.StockItemId }).IsUnique();
});
// CuttingTool
@@ -282,34 +242,6 @@ public class ApplicationDbContext : DbContext
.OnDelete(DeleteBehavior.SetNull);
});
// PurchaseItem
modelBuilder.Entity<PurchaseItem>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Notes).HasMaxLength(500);
entity.Property(e => e.Status)
.HasMaxLength(20)
.HasConversion(
v => v.ToString(),
v => Enum.Parse<PurchaseItemStatus>(v));
entity.Property(e => e.CreatedAt).HasDefaultValueSql("GETUTCDATE()");
entity.HasOne(e => e.StockItem)
.WithMany()
.HasForeignKey(e => e.StockItemId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(e => e.Supplier)
.WithMany()
.HasForeignKey(e => e.SupplierId)
.OnDelete(DeleteBehavior.SetNull);
entity.HasOne(e => e.Job)
.WithMany()
.HasForeignKey(e => e.JobId)
.OnDelete(DeleteBehavior.SetNull);
});
// Seed default cutting tools
modelBuilder.Entity<CuttingTool>().HasData(
new CuttingTool { Id = 1, Name = "Bandsaw", KerfInches = 0.0625m, IsDefault = true, IsActive = true },
-25
View File
@@ -1,25 +0,0 @@
namespace CutList.Web.Data.Entities;
public enum PurchaseItemStatus
{
Pending,
Ordered,
Received
}
public class PurchaseItem
{
public int Id { get; set; }
public int StockItemId { get; set; }
public int? SupplierId { get; set; }
public int Quantity { get; set; }
public int? JobId { get; set; }
public string? Notes { get; set; }
public PurchaseItemStatus Status { get; set; } = PurchaseItemStatus.Pending;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime? UpdatedAt { get; set; }
public StockItem StockItem { get; set; } = null!;
public Supplier? Supplier { get; set; }
public Job? Job { get; set; }
}
-1
View File
@@ -13,6 +13,5 @@ public class StockItem
public DateTime? UpdatedAt { get; set; }
public Material Material { get; set; } = null!;
public ICollection<SupplierOffering> SupplierOfferings { get; set; } = new List<SupplierOffering>();
public ICollection<StockTransaction> Transactions { get; set; } = new List<StockTransaction>();
}
@@ -7,14 +7,11 @@ public class StockTransaction
public int Quantity { get; set; }
public StockTransactionType Type { get; set; }
public int? JobId { get; set; }
public int? SupplierId { get; set; }
public decimal? UnitPrice { get; set; }
public string? Notes { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public StockItem StockItem { get; set; } = null!;
public Job? Job { get; set; }
public Supplier? Supplier { get; set; }
}
public enum StockTransactionType
-13
View File
@@ -1,13 +0,0 @@
namespace CutList.Web.Data.Entities;
public class Supplier
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string? ContactInfo { get; set; }
public string? Notes { get; set; }
public bool IsActive { get; set; } = true;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public ICollection<SupplierOffering> Offerings { get; set; } = new List<SupplierOffering>();
}
@@ -1,16 +0,0 @@
namespace CutList.Web.Data.Entities;
public class SupplierOffering
{
public int Id { get; set; }
public int StockItemId { get; set; }
public int SupplierId { get; set; }
public string? PartNumber { get; set; }
public string? SupplierDescription { get; set; }
public decimal? Price { get; set; }
public string? Notes { get; set; }
public bool IsActive { get; set; } = true;
public StockItem StockItem { get; set; } = null!;
public Supplier Supplier { get; set; } = null!;
}