Files
Lizandro GuarnizoandClaude Sonnet 5 a25329c7b1 fix(umind): libera las columnas huérfanas que dejó el refactor multi-agente
Error en producción al crear un tenant:

    null value in column "site_key" of relation "umind_tenants"
    violates not-null constraint (SQLSTATE 23502)

Es un bug que introduje yo. Al pasar uMind a multi-agente saqué SiteKey de
UmindTenant y renombré TenantID→AgenteID en seis tablas. GORM agrega
columnas pero nunca las borra ni les cambia las restricciones, así que las
viejas quedaron en la base CON su NOT NULL original — y el INSERT nuevo ya
no las incluye.

Al mirarlo, el alcance era mayor que el error reportado: no es solo
site_key. Las seis tablas renombradas tienen su tenant_id huérfano también
NOT NULL, así que fallaba insertar documentos, chunks, mensajes, tools,
canales y conexiones. En la práctica uMind quedaba inutilizable después de
desplegar el refactor: ni crear un tenant, ni ingestar conocimiento, ni
guardar un mensaje del chat.

La migración corre en cada arranque, antes de MigrarUmindAgentes, y
consulta information_schema para no intentar el ALTER a ciegas en una
instalación nueva donde la columna no existe.

No se hace DROP COLUMN a propósito: los datos viejos quedan por si hay que
reconciliar algo. Solo se libera la restricción.

El test compara los nombres de tabla contra el TableName() real de cada
modelo. Un typo ahí haría que la migración no encuentre la columna y siga
de largo: el bug seguiría vivo y el arranque se vería sano.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-15 07:45:17 -05:00

73 lines
2.8 KiB
Go

package controllers
import (
"log"
"github.com/gofiber/fiber/v2"
"github.com/sujit-baniya/fiber-boilerplate/pkg/services"
)
// Estructuras definidas por el cliente (ya están bien)
type Address struct {
Name string `json:"name"`
Line1 string `json:"line_1"`
Line2 string `json:"line_2"`
Line3 string `json:"line_3"`
City string `json:"city"`
State string `json:"state"`
Country string `json:"country"`
Zip string `json:"zip"`
PhoneNumber string `json:"phone_number"`
Metadata map[string]interface{} `json:"metadata"`
Canton string `json:"canton"`
District string `json:"district"`
}
type Contact struct {
PhoneNumber string `json:"phone_number"`
Email string `json:"email"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
MothersName string `json:"mothers_name"`
ContactType string `json:"contact_type"`
Address Address `json:"address"`
IdentificationType string `json:"identification_type"`
IdentificationNumber string `json:"identification_number"`
DateOfBirth string `json:"date_of_birth"`
Country string `json:"country"`
Nationality string `json:"nationality"`
Metadata map[string]interface{} `json:"metadata"`
}
type WalletRequest struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
EwalletReferenceID string `json:"ewallet_reference_id"`
Metadata map[string]interface{} `json:"metadata"`
Type string `json:"type"`
Contact Contact `json:"contact"`
}
func MakeWallet(c *fiber.Ctx) error {
var body WalletRequest
// 1. Parsear el cuerpo de la solicitud
if err := c.BodyParser(&body); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"error": "Error al parsear el cuerpo de la solicitud: " + err.Error(),
})
}
// El cuerpo de un wallet lleva nombre, correo, teléfono, documento y fecha
// de nacimiento: no se loguea.
response, err := services.MakeRequest("post", "/v1/ewallets", body)
if err != nil {
log.Printf("[RAPYD] error creando wallet: %v", err)
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": "Error al comunicarse con Rapyd",
"details": err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(response)
}