SPMS_API/SPMS.Infrastructure/Persistence/Configurations/DeviceConfiguration.cs

41 lines
1.8 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SPMS.Domain.Entities;
namespace SPMS.Infrastructure.Persistence.Configurations;
public class DeviceConfiguration : IEntityTypeConfiguration<Device>
{
public void Configure(EntityTypeBuilder<Device> builder)
{
builder.ToTable("Device");
builder.HasKey(e => e.Id);
builder.Property(e => e.Id).ValueGeneratedOnAdd();
builder.Property(e => e.ServiceId).IsRequired();
builder.Property(e => e.ExternalDeviceId).HasMaxLength(36).IsRequired();
builder.Property(e => e.DeviceToken).HasMaxLength(255).IsRequired();
builder.Property(e => e.Platform).HasColumnType("tinyint").IsRequired();
builder.Property(e => e.AppVersion).HasMaxLength(20);
builder.Property(e => e.OsVersion).HasMaxLength(20);
builder.Property(e => e.DeviceModel).HasMaxLength(50);
builder.Property(e => e.Tags).HasColumnType("json");
builder.Property(e => e.PushAgreed).HasColumnType("tinyint(1)").IsRequired();
builder.Property(e => e.MarketingAgreed).HasColumnType("tinyint(1)").IsRequired();
builder.Property(e => e.IsActive).HasColumnType("tinyint(1)").IsRequired().HasDefaultValue(true);
builder.Property(e => e.CreatedAt).IsRequired();
builder.Property(e => e.UpdatedAt);
builder.Property(e => e.AgreeUpdatedAt);
builder.Property(e => e.MktAgreeUpdatedAt);
builder.HasOne(e => e.Service)
.WithMany(s => s.Devices)
.HasForeignKey(e => e.ServiceId)
.OnDelete(DeleteBehavior.Restrict);
builder.HasIndex(e => new { e.ServiceId, e.ExternalDeviceId }).IsUnique();
builder.HasIndex(e => new { e.ServiceId, e.DeviceToken });
}
}