Skip to content

Instantly share code, notes, and snippets.

@travisbutterfield
Last active May 20, 2023 15:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travisbutterfield/f905795c911faca5b0d3b6d037b63816 to your computer and use it in GitHub Desktop.
Save travisbutterfield/f905795c911faca5b0d3b6d037b63816 to your computer and use it in GitHub Desktop.

Connecting separate DDEV containers for migration

Using some of the information from this article, and information from a few other sources, I have come up with a procedure for connecting two separate local DDEV containers for Drupal 7 to Drupal 9 migration work.

  1. Create your Drupal 7 container from the source. In this case, we will be using a Pantheon-based website.
  2. Create your new Webspark 2 (Drupal 9) site in Pantheon.
  3. Install and enable modules in the new D9 site. (If you want to migrate content from D7 that is related to a module in any way, you will have to install that module in your D9 site, or the Migrate API won’t know to include it.)
    • Use Composer to require modules: ddev composer require 'drupal/migrate_plus:^5.1' 'drupal/migrate_tools:^5.0' 'drupal/migrate_upgrade:^3.2'
    • Enable modules using Drush (this includes some core and migration modules, but you can enable whatever you need): ddev drush --yes en migrate_drupal migrate_plus migrate_tools migrate_upgrade
  4. Add drupal7 database connection info to the web/sites/default/settings.php or web/sites/default/settings.local.php file in the D9 site:
$databases['migrate']['default'] = array (
   'database' => 'db',
   'username' => 'db',
   'password' => 'db',
   'prefix' => '',
   'host' => 'ddev-<sitename>-db',
   'port' => 3306,
   'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
   'driver' => 'mysql',
 );
  1. Clear caches. Then verify that Drupal 9 can connect to the Drupal 7 database: ddev drush cr; ddev $(drush sql-connect --database=migrate)
  2. Run migrate:upgrade --configure-only to get the migration YAML files: ddev drush --yes migrate:upgrade --legacy-db-key='migrate' --legacy-root='http://ddev-<sitename>-web' --configure-only
  3. Export the configuration to code: ddev drush --yes config:export
@minordv8
Copy link

@travisbutterfield I noticed that the link to the article on Aquia dev blog is no longer valid. I also found that on step 4 I was unable to connect to run the "ddev $(drush sql-connect --database=migrate)" command when I added the DB info to the settings.local.php file but when I added this to the settings.php I was able to connect. Maybe something I missed while setting up the local ddev environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment