There’s so much going on in the world of Drupal migrations. Drupal 9 reached its End Of Life (EOL) on November 1, 2023. Drupal 7 will reach EOL by January 2025 (final extension). Drupal 10 was released back in December 2022 and its current version, 10.1.6 was released on November 1, 2023. More than twelve thousand sites have already migrated to the current version of Drupal 10 (according to the Upgrade Status module download stats).

In this article, we’ll take you through the different Drupal migration methods and especially focus on custom migrations using the SqlBase source plugin. Take a look!

In Technical Terms, What is a Drupal Migration?

Drupal migration is the process of moving content, data, and configuration from another CMS (or an older version of Drupal) to Drupal. A migration consists of several steps: Extract, Transform, and Load (ETL). In the Drupal world, we refer to these as source plugins, process plugins, and destination plugins. The Extract phase is known as the source, Transform is the process, and Load is the destination.

Drupal Migration Methods

When migrating your website from Drupal 7 to Drupal 9 or a later version, there are primarily two migration methods available.

  • Migration UI 
  • Drush (Custom migration)

Migration UI 

When you want to migrate your entire web application, including all configurations and content, to a later version, you can use Migration UI. It's a straightforward option that doesn't require in-depth knowledge of Drupal APIs. This approach can be used where your site is not too complex in terms of site architecture and considering all the modules used in Drupal 7 are also available in the target version (Drupal 9 or Drupal 10).

Custom Migration

When you are rewriting your website with a more modern and performance-centric approach which leads to significant changes in the architecture of your new website from Drupal 9, Migration UI literally won’t work. In such cases, you’ll need to roll up your sleeves and build custom migration scripts.

Migration Process

Let’s dig deeper into the migration process. It comprises of 3 major processes.

  • Source plugin (Extract)
  • Process plugin (Transform)
  • Destination plugin (Load)

Source Plugin

Source plugins handle the extraction of data from various sources, which can be in different formats, including raw data, databases, and CSV/XML/JSON files. They extract data from these sources and pass it on to the next phase in the migration process.

Process Plugin

The process plugin works on the source data, restructuring it to match the destination process. It transforms the data into an array, where each key corresponds to a destination property. The values assigned to each key determine how the destination values for your new website are generated.

More details can be found here.

Destination plugin

The destination plugin processes the structured data and saves it on your website. The most common destination plugins are node, term, user, and media.

You likely have a grasp of the migration process. Now, let's delve deeper into source plugins, with a specific focus on the SqlBase source plugin.

Thinking of migrating your Drupal 7 website to Drupal 10? Get your Drupal 7 Site Audit report for Free!

Using SqlBase for the Drupal Migration

What is SqlBase migration?

SqlBase migration is straightforward—it allows you the flexibility to create your custom SQL queries to obtain the desired output. Other than that, it follows the same principles as other Drupal migration methods.

Why should you use SqlBase Migration?

When your site has a straightforward field structure, content types, etc., Drupal core migration can handle it. However, challenges arise with obsolete field types in Drupal 9 or when restructuring an old website with various content types. If you aim for an editor-friendly and performance-oriented site, a simple migration won't suffice. You'll need to prepare your source data and take the SqlBase migration route.

In another scenario, if your current site, built on a platform other than Drupal, provides data in the form of a database, SqlBase migration is also the way to go.

Benefits of leveraging SqlBase Migration

Since this is SqlBase, the speed of your migration relies entirely on how well you craft your database queries. The better your query preparation, the faster the migration will run.

It doesn't rely on many core migration processes; you have the flexibility to shape and process your data as you see fit.

The SqlBase Source Plugin must implement these three methods:

  • query(): Returns the SQL query that selects the data from the source database.
  • fields(): Returns available fields on the source.
  • getIds(): Defines the source fields uniquely identifying a source row

Let’s get into the details of what these functions should contain:

query() function

/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('job_details', 'c')
  ->fields('c', array(
    'id',
    'title',
    'description',o
    'position',
    'company',
    'criteria',
  ));
return $query;
}


fields() function

/**
* {@inheritdoc}
*/
public function fields() {
$fields = array(
  'id'= $this->t('Autoincrement ID'),
  'title' = $this->t('Job Title'),
  'description' = $this->t('Job Description'),
  'position' = $this->t('Job Position'),
  'company'.= $this->t('Company'),
  'criteria' = $this-»t('Job Criteria'),
);
return $fields;
}

getIds() function

/**
* {@inheritdoc}
*/
public function getIds() {
return [
  'id' => [
  'type' => 'integer',
  'alias'=>'j'
];
}


Additionally, you can tweak your SQL result by using the prepareRow() function and even add new source properties to your migration.

/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$company = $row->getSourceProperty('company');

$row->setSourceProperty('job_type', 'on-site');
if ($company == 'specbee') {
  $row->setSourceProperty('job_type', 'remote');
}

return parent::prepareRow($row);
}

These source properties will be sent to your migration yml files and you can also use your own processor if you want any additional processing on your source data.


References
https://www.drupal.org/project/usage/3398311

Final Thoughts

With Drupal 9's EOL, the impending farewell to Drupal 7, and the rise of Drupal 10, the need for seamless transitions has never been more pressing. As Drupal evolves, our Drupal Development Company recognizes SqlBase as an essential tool for a seamless and efficient migration process. Offering the flexibility to shape personalized SQL queries, it plays a vital role in crafting tailored data transitions. If you’re looking for a reliable Drupal migration partner, we’re just a form away!
 

Contact us

LET'S DISCUSS YOUR IDEAS. 
WE'D LOVE TO HEAR FROM YOU.

CONTACT US