SET @sunat_usuario_exists := (
    SELECT COUNT(*)
    FROM information_schema.columns
    WHERE table_schema = DATABASE()
      AND table_name = 'empresas'
      AND column_name = 'sunat_usuario_secundario'
);

SET @sql_sunat_usuario := IF(
    @sunat_usuario_exists = 0,
    'ALTER TABLE empresas ADD COLUMN sunat_usuario_secundario VARCHAR(120) NULL AFTER giro_negocio_id',
    'SELECT 1'
);
PREPARE stmt_sunat_usuario FROM @sql_sunat_usuario;
EXECUTE stmt_sunat_usuario;
DEALLOCATE PREPARE stmt_sunat_usuario;

SET @sunat_clave_exists := (
    SELECT COUNT(*)
    FROM information_schema.columns
    WHERE table_schema = DATABASE()
      AND table_name = 'empresas'
      AND column_name = 'sunat_clave_secundaria'
);

SET @sql_sunat_clave := IF(
    @sunat_clave_exists = 0,
    'ALTER TABLE empresas ADD COLUMN sunat_clave_secundaria VARCHAR(255) NULL AFTER sunat_usuario_secundario',
    'SELECT 1'
);
PREPARE stmt_sunat_clave FROM @sql_sunat_clave;
EXECUTE stmt_sunat_clave;
DEALLOCATE PREPARE stmt_sunat_clave;
