feat: Implementato sistema di associazioni chiave per prevenire duplicati nel data coupling
BREAKING CHANGE: Rimosso completamente il vecchio sistema RecordAssociation Modifiche principali: - Sostituito RecordAssociation con KeyAssociation basato sui valori delle chiavi - Implementata logica robusta di UPDATE vs INSERT basata su associazioni esistenti - Aggiunta normalizzazione delle chiavi (.Trim()) per consistenza - Implementato fallback nella ricerca associazioni per maggiore affidabilità - Sostituita verifica pre-UPDATE con tentativo diretto più efficiente Componenti modificati: - Nuovo modello: KeyAssociation.cs con campi ottimizzati - Nuovo servizio: KeyAssociationService.cs con metodi completi - Aggiornato: DataCoupler.razor con logica migliorata di gestione associazioni - Aggiornato: CredentialDbContext per gestire solo KeyAssociations - Aggiornati: tutti i servizi di interfaccia per supportare il nuovo sistema - Creata: pagina KeyAssociations.razor per gestione associazioni - Aggiornato: NavMenu.razor con link alla gestione associazioni Miglioramenti tecnici: - Logica di UPDATE più robusta: tenta direttamente l'aggiornamento invece di verificare prima l'esistenza - Gestione errori migliorata con cleanup automatico delle associazioni non valide - Debug logging estensivo per troubleshooting - Fallback nella ricerca associazioni se parametri specifici falliscono - Normalizzazione valori chiave per prevenire problemi di whitespace Risultato: Il sistema ora previene correttamente i duplicati utilizzando le associazioni per decidere se fare INSERT (nuovo record) o UPDATE (record esistente) basandosi sui valori delle chiavi. Database: - Creata migrazione EF per rimuovere RecordAssociations e aggiungere KeyAssociations - Eliminati file e codice legacy non più necessari
This commit is contained in:
@@ -9,7 +9,7 @@ namespace CredentialManager.Data;
|
||||
public class CredentialDbContext : DbContext
|
||||
{
|
||||
public DbSet<CredentialEntity> Credentials { get; set; }
|
||||
public DbSet<RecordAssociation> RecordAssociations { get; set; }
|
||||
public DbSet<KeyAssociation> KeyAssociations { get; set; }
|
||||
|
||||
public CredentialDbContext(DbContextOptions<CredentialDbContext> options) : base(options)
|
||||
{
|
||||
@@ -86,24 +86,24 @@ public class CredentialDbContext : DbContext
|
||||
entity.HasIndex(e => e.IsActive);
|
||||
});
|
||||
|
||||
// Configurazione della tabella RecordAssociations
|
||||
modelBuilder.Entity<RecordAssociation>(entity =>
|
||||
// Configurazione della tabella KeyAssociations
|
||||
modelBuilder.Entity<KeyAssociation>(entity =>
|
||||
{
|
||||
entity.ToTable("RecordAssociations");
|
||||
entity.ToTable("KeyAssociations");
|
||||
|
||||
entity.HasKey(e => e.Id);
|
||||
|
||||
entity.Property(e => e.SourceName)
|
||||
entity.Property(e => e.KeyValue)
|
||||
.IsRequired()
|
||||
.HasMaxLength(500);
|
||||
|
||||
entity.Property(e => e.SourceKeyField)
|
||||
.IsRequired()
|
||||
.HasMaxLength(200);
|
||||
|
||||
entity.Property(e => e.SourceType)
|
||||
entity.Property(e => e.DestinationKeyField)
|
||||
.IsRequired()
|
||||
.HasMaxLength(50);
|
||||
|
||||
entity.Property(e => e.SourceKey)
|
||||
.IsRequired()
|
||||
.HasMaxLength(500);
|
||||
.HasMaxLength(200);
|
||||
|
||||
entity.Property(e => e.DestinationEntity)
|
||||
.IsRequired()
|
||||
@@ -117,6 +117,9 @@ public class CredentialDbContext : DbContext
|
||||
.IsRequired()
|
||||
.HasMaxLength(100);
|
||||
|
||||
entity.Property(e => e.SourcesInfo)
|
||||
.HasMaxLength(2000);
|
||||
|
||||
entity.Property(e => e.AdditionalInfo)
|
||||
.HasMaxLength(2000);
|
||||
|
||||
@@ -125,15 +128,18 @@ public class CredentialDbContext : DbContext
|
||||
.HasDefaultValue(true);
|
||||
|
||||
// Indici
|
||||
entity.HasIndex(e => new { e.SourceName, e.SourceKey, e.DestinationEntity })
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_RecordAssociations_Unique");
|
||||
entity.HasIndex(e => e.KeyValue)
|
||||
.HasDatabaseName("IX_KeyAssociations_KeyValue");
|
||||
|
||||
entity.HasIndex(e => new { e.KeyValue, e.DestinationEntity, e.RestCredentialName })
|
||||
.IsUnique()
|
||||
.HasDatabaseName("IX_KeyAssociations_Unique");
|
||||
|
||||
entity.HasIndex(e => e.SourceType);
|
||||
entity.HasIndex(e => e.DestinationEntity);
|
||||
entity.HasIndex(e => e.RestCredentialName);
|
||||
entity.HasIndex(e => e.IsActive);
|
||||
entity.HasIndex(e => e.CreatedAt);
|
||||
entity.HasIndex(e => e.LastVerifiedAt);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user