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). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: Video.js (HTML5 Video Player) 10.0.0-alpha1 First alpha version released for module videojs (10.0.0-alpha1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Custom SQL Migrate Source Plugin

98 sites Security covered Drupal 8–11
View on drupal.org

This module allows you to pull data directly from any database using a custom SQL query defined in your migration configuration. The results of your query are then available for use in any process plugin or as a source for fields.

Prerequisites:
Existing database entered in the settings.php file.
In this example:

$databases['mg_legacy']['default'] = array (
  'database' => 'mg_legacy',
  'username' => 'xxx',
  'password' => 'xxx',
  'host' => 'localhost',
  'port' => '3306',
  'driver' => 'mysql',
  'prefix' => '',
  'collation' => 'utf8mb4_general_ci',
);

Installation:
Enable module

Description:
With this CustomSQLQuery plugin you can enter a custom SQL string in your migration config file and it will pull the data directly from any database.

It returns all the fields queried in the SQL string in the row object. So any field you select in the SQL query can be accessed by any process plugin or as a source for any field.

IMPORTANT: Any changes to the sql requires you to re-install your custom migration module for the settings to take affect. You can do so with

drush pmu [module_name] -y && drush en [module_name] -y

Please see config below as an example:

id: resources
label: Resources
migration_group: mmg8_legacy_migrations
migration_dependencies:
  required:
    - mmg8_legacy_migrations_article_type
source:
  plugin: custom_sql_query
  key: mg_legacy
  keys:
    - id
  sql_query: 'SELECT resources.id,
                     CONCAT(''/'', resources.slug) as slug,
                     resources.title,
                     resources.description,
                     resources.file,
                     resources.published,
                     resources.category_id,
                     resources.created_at,
                     resources.updated_at,
                     resources.locked,
                     resources.subtitle,
                     resources.archive
                FROM resources resources'
destination:
  plugin: entity:node
  default_bundle: article
process:
  title: title
  path/pathauto:
    plugin: default_value
    default_value: 0 # Disable pathauto.
  path/alias: slug

Depends on

Dependencies of the latest stable release

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
3
Tracked since
Jul 2025
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 3
Maintenance
Dormant

Release Timeline

Releases

Version Type Core Release date
8.x-1.5 Stable 8–11 Jul 9, 2025
8.x-1.4 Stable 8–11 Jul 8, 2025
8.x-1.x-dev Dev 8–11 Jul 2, 2025