Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Migrate Batch

2 sites Security covered
View on drupal.org

This module enhances Drupal's migration system by allowing you to process migration items in batches with automatic progress tracking. It keeps track of the migration's state between runs, enabling continuous cycling through all source items.

A Drupal module that provides batch migration processing with automatic offset tracking.

Features

This module extends Drupal's migration system by providing commands to process migration items in configurable batches with automatic progress tracking. Unlike standard drush migrate:import --limit, these commands maintain state between runs and can cycle through all source items continuously.

Usage

You can use the migrate_batch service directly in your custom modules, hooks, or other Drupal code:

/** @var \Drupal\migrate_batch\Service\MigrateBatchService $batch */
$batch = \Drupal::service('migrate_batch');

// Process a batch of default item amount (20).
$batch->next('my_migration');

// Process next batch of 50 items.
$batch->next('my_migration', 50);

// Process 50 items starting from offset 100.
$batch->next('my_migration', 50, 100);

// Check current offset.
$offset = $batch->getOffset('my_migration');
echo "Current offset: $offset";

// Set offset to a specific value.
$batch->setOffset('my_migration', 100);

// Reset offset back to 0.
$batch->resetOffset('my_migration');

Note: The service automatically tracks progress using Drupal's State API. Each call to next() processes the next batch and advances the offset.

Integration

This module works with any Drupal migration. For optimal performance with large datasets, source plugins should use the BatchableSourceTrait to support batch processing:

Source Plugin Integration

The BatchableSourceTrait provides three key methods for batch processing:

  • isBatchRequest(): Returns TRUE when the migration is running in batch mode
  • getBatchLimit(): Returns the number of items to process in this batch
  • getBatchOffset(): Returns the starting position for this batch

Use these methods in your source plugin's initializeIterator() method to apply LIMIT and OFFSET to your data retrieval

For more details, see the examples in the README.

Drush Commands

drush migrate:batch-next (alias: mbn)
Main command for processing the next batch of migration items.

drush migrate:batch-offset (alias: mbo)
Check the current batch offset for a migration.

drush migrate:batch-offset:set (alias: mbos)
Set the batch offset for a migration to a specific value.

drush migrate:batch-offset:reset (alias: mbor)
Reset the batch offset for a migration back to 0.

Additional Requirements

  • drupal:migrate - provides the Migrate API

Similar projects

Supporting this Module

Community Documentation

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
4
Tracked since
Sep 2025
Latest release
10 months ago
Releases (12 mo)
4 ▲ from 0
Maintenance
Slowing

Release Timeline

Releases

Version Type Core Release date
1.0.0-beta2 Pre-release 10–11 Oct 3, 2025
1.0.0-beta1 Pre-release 10–11 Sep 29, 2025
1.0.0-alpha1 Pre-release 10–11 Sep 27, 2025
1.x-dev Dev 10–11 Sep 27, 2025