initial commit
This commit is contained in:
113
backend/Infrastructure/Data/Configurations/SpoolConfiguration.cs
Normal file
113
backend/Infrastructure/Data/Configurations/SpoolConfiguration.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using Extrudex.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Extrudex.Infrastructure.Data.Configurations;
|
||||
|
||||
public class SpoolConfiguration : BaseEntityConfiguration<Spool>
|
||||
{
|
||||
public override void Configure(EntityTypeBuilder<Spool> builder)
|
||||
{
|
||||
base.Configure(builder);
|
||||
|
||||
builder.Property(e => e.MaterialBaseId)
|
||||
.HasColumnName("material_base_id")
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(e => e.MaterialFinishId)
|
||||
.HasColumnName("material_finish_id")
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(e => e.MaterialModifierId)
|
||||
.HasColumnName("material_modifier_id");
|
||||
|
||||
builder.Property(e => e.Brand)
|
||||
.HasColumnName("brand")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.Property(e => e.ColorName)
|
||||
.HasColumnName("color_name")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.Property(e => e.ColorHex)
|
||||
.HasColumnName("color_hex")
|
||||
.IsRequired()
|
||||
.HasMaxLength(7); // "#RRGGBB" format
|
||||
|
||||
builder.Property(e => e.WeightTotalGrams)
|
||||
.HasColumnName("weight_total_grams")
|
||||
.HasPrecision(10, 2)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(e => e.WeightRemainingGrams)
|
||||
.HasColumnName("weight_remaining_grams")
|
||||
.HasPrecision(10, 2)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(e => e.FilamentDiameterMm)
|
||||
.HasColumnName("filament_diameter_mm")
|
||||
.HasPrecision(6, 3)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(e => e.SpoolSerial)
|
||||
.HasColumnName("spool_serial")
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
builder.Property(e => e.PurchasePrice)
|
||||
.HasColumnName("purchase_price")
|
||||
.HasPrecision(10, 2);
|
||||
|
||||
builder.Property(e => e.PurchaseDate)
|
||||
.HasColumnName("purchase_date");
|
||||
|
||||
builder.Property(e => e.IsActive)
|
||||
.HasColumnName("is_active")
|
||||
.HasDefaultValue(true)
|
||||
.IsRequired();
|
||||
|
||||
// Unique index on spool_serial — critical for barcode/QR scanning
|
||||
builder.HasIndex(e => e.SpoolSerial)
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_spools_spool_serial");
|
||||
|
||||
// Index on material_base_id for spool filtering
|
||||
builder.HasIndex(e => e.MaterialBaseId)
|
||||
.HasDatabaseName("ix_spools_material_base_id");
|
||||
|
||||
// Index on is_active for active spool queries
|
||||
builder.HasIndex(e => e.IsActive)
|
||||
.HasDatabaseName("ix_spools_is_active");
|
||||
|
||||
// Relationships
|
||||
builder.HasOne(e => e.MaterialBase)
|
||||
.WithMany(e => e.Spools)
|
||||
.HasForeignKey(e => e.MaterialBaseId)
|
||||
.HasConstraintName("fk_spools_material_base")
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(e => e.MaterialFinish)
|
||||
.WithMany(e => e.Spools)
|
||||
.HasForeignKey(e => e.MaterialFinishId)
|
||||
.HasConstraintName("fk_spools_material_finish")
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.HasOne(e => e.MaterialModifier)
|
||||
.WithMany(e => e.Spools)
|
||||
.HasForeignKey(e => e.MaterialModifierId)
|
||||
.HasConstraintName("fk_spools_material_modifier")
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
builder.HasMany(e => e.AmsSlots)
|
||||
.WithOne(e => e.Spool!)
|
||||
.HasForeignKey(e => e.SpoolId)
|
||||
.HasConstraintName("fk_ams_slots_spool");
|
||||
|
||||
builder.HasMany(e => e.PrintJobs)
|
||||
.WithOne(e => e.Spool)
|
||||
.HasForeignKey(e => e.SpoolId)
|
||||
.HasConstraintName("fk_print_jobs_spool");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user