24 lines
995 B
SQL
24 lines
995 B
SQL
-- Migración: Agregar campo mechanic_employee_code a la tabla inspections
|
|
-- Fecha: 2025-11-26
|
|
-- Descripción: Agrega un campo para almacenar el código de operario del mecánico que realiza la inspección
|
|
|
|
-- Agregar columna mechanic_employee_code a la tabla inspections
|
|
ALTER TABLE inspections
|
|
ADD COLUMN IF NOT EXISTS mechanic_employee_code VARCHAR(50);
|
|
|
|
-- Comentario descriptivo
|
|
COMMENT ON COLUMN inspections.mechanic_employee_code IS 'Código de operario del mecánico que realiza la inspección (copiado del perfil de usuario)';
|
|
|
|
-- Actualizar inspecciones existentes con el employee_code del mecánico correspondiente
|
|
UPDATE inspections i
|
|
SET mechanic_employee_code = u.employee_code
|
|
FROM users u
|
|
WHERE i.mechanic_id = u.id
|
|
AND i.mechanic_employee_code IS NULL;
|
|
|
|
-- Verificar que la columna se agregó correctamente
|
|
SELECT column_name, data_type, character_maximum_length
|
|
FROM information_schema.columns
|
|
WHERE table_name = 'inspections'
|
|
AND column_name = 'mechanic_employee_code';
|