04f0403f12
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
140 lines
6.7 KiB
C#
140 lines
6.7 KiB
C#
using System;
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
#nullable disable
|
|
|
|
namespace CredentialManager.Migrations
|
|
{
|
|
/// <inheritdoc />
|
|
public partial class ReplaceRecordAssociationsWithKeyAssociations : Migration
|
|
{
|
|
/// <inheritdoc />
|
|
protected override void Up(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.CreateTable(
|
|
name: "Credentials",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
Type = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
|
|
DatabaseType = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
|
ConnectionString = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
|
|
Host = table.Column<string>(type: "TEXT", maxLength: 200, nullable: true),
|
|
Port = table.Column<int>(type: "INTEGER", nullable: true),
|
|
DatabaseName = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
Username = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
EncryptedPassword = table.Column<string>(type: "TEXT", nullable: true),
|
|
EncryptedApiKey = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
|
|
EncryptedAuthToken = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
|
|
CommandTimeout = table.Column<int>(type: "INTEGER", nullable: false, defaultValue: 30),
|
|
TimeoutSeconds = table.Column<int>(type: "INTEGER", nullable: false, defaultValue: 100),
|
|
IgnoreSslErrors = table.Column<bool>(type: "INTEGER", nullable: false, defaultValue: false),
|
|
RestServiceType = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
|
Headers = table.Column<string>(type: "TEXT", maxLength: 2000, nullable: true),
|
|
AdditionalParameters = table.Column<string>(type: "TEXT", maxLength: 2000, nullable: true),
|
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
|
|
CreatedBy = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
|
IsActive = table.Column<bool>(type: "INTEGER", nullable: false, defaultValue: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_Credentials", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateTable(
|
|
name: "KeyAssociations",
|
|
columns: table => new
|
|
{
|
|
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
|
.Annotation("Sqlite:Autoincrement", true),
|
|
KeyValue = table.Column<string>(type: "TEXT", maxLength: 500, nullable: false),
|
|
SourceKeyField = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
|
|
DestinationKeyField = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
|
|
DestinationEntity = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
|
|
DestinationId = table.Column<string>(type: "TEXT", maxLength: 200, nullable: false),
|
|
RestCredentialName = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
|
|
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false),
|
|
UpdatedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
|
|
LastVerifiedAt = table.Column<DateTime>(type: "TEXT", nullable: true),
|
|
IsActive = table.Column<bool>(type: "INTEGER", nullable: false, defaultValue: true),
|
|
SourcesInfo = table.Column<string>(type: "TEXT", maxLength: 2000, nullable: true),
|
|
AdditionalInfo = table.Column<string>(type: "TEXT", maxLength: 2000, nullable: true)
|
|
},
|
|
constraints: table =>
|
|
{
|
|
table.PrimaryKey("PK_KeyAssociations", x => x.Id);
|
|
});
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Credentials_DatabaseType",
|
|
table: "Credentials",
|
|
column: "DatabaseType");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Credentials_IsActive",
|
|
table: "Credentials",
|
|
column: "IsActive");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Credentials_Name",
|
|
table: "Credentials",
|
|
column: "Name",
|
|
unique: true);
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_Credentials_Type",
|
|
table: "Credentials",
|
|
column: "Type");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_KeyAssociations_CreatedAt",
|
|
table: "KeyAssociations",
|
|
column: "CreatedAt");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_KeyAssociations_DestinationEntity",
|
|
table: "KeyAssociations",
|
|
column: "DestinationEntity");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_KeyAssociations_IsActive",
|
|
table: "KeyAssociations",
|
|
column: "IsActive");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_KeyAssociations_KeyValue",
|
|
table: "KeyAssociations",
|
|
column: "KeyValue");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_KeyAssociations_LastVerifiedAt",
|
|
table: "KeyAssociations",
|
|
column: "LastVerifiedAt");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_KeyAssociations_RestCredentialName",
|
|
table: "KeyAssociations",
|
|
column: "RestCredentialName");
|
|
|
|
migrationBuilder.CreateIndex(
|
|
name: "IX_KeyAssociations_Unique",
|
|
table: "KeyAssociations",
|
|
columns: new[] { "KeyValue", "DestinationEntity", "RestCredentialName" },
|
|
unique: true);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void Down(MigrationBuilder migrationBuilder)
|
|
{
|
|
migrationBuilder.DropTable(
|
|
name: "Credentials");
|
|
|
|
migrationBuilder.DropTable(
|
|
name: "KeyAssociations");
|
|
}
|
|
}
|
|
}
|