Renaming (migrating in place) appears to be broken. Migrations across platforms appears to work, but when selecting the same platform, the new DB appears to be dropped, despite the new credentials being written into the vhost and drushrc. So the site breaks completely. Thankfully, the old database remains, so it's possible to recover, but only through manual intervention

CommentFileSizeAuthor
#5 provision-2055949-5.patch431 bytesergonlogic
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ergonlogic’s picture

Here's a task log from a dev environment: http://pastebin.com/DAGxA6wz

The code in question is this in db/migrate.provision.inc:

// Deletes the old database credentials
function drush_db_post_provision_migrate() {
  d()->service('db')->destroy_site_database();
}
ergonlogic’s picture

Title: Rename (migrate in place) fails resulting in broken site » Migrate drops wrong database when domain name changes

Actually, this is occurring whenever the domain name changes during a migration.

It's worth noting also that the task itself doesn't fail, per se. No error is thrown or anything like that. It just drops the new DB instead of the old one and then proceeds to delete the old site files.

Updated title to reflect this.

ergonlogic’s picture

Okay, I think the problem here is with how we call destroy_site_database():

function destroy_site_database($creds = array()) {
  if (!sizeof($creds)) {
    $creds = $this->fetch_site_credentials();
  }
  extract($creds);

  if ( $this->database_exists($db_name) ) {
    drush_log(dt("Dropping database @dbname", array('@dbname' => $db_name)));
    if (!$this->drop_database($db_name)) {
      drush_log(dt("Failed to drop database @dbname", array('@dbname' => $db_name)), 'warning');
    }
  }

This method's parameter is optional, and we rely on fetch_site_credentials() to look up the proper site if none is provided. This in turn just looks at the current Drush 'site' context, which in this case has the credential for the new site. So, we could try to switch the site context credentials back to the original site. BTW, I think this might have been at the root of #1678528: Database deleted on edge cases.

But I believe we should be more conservative here. In all five instances where we call destroy_site_database() in Aegir core, we never pass in $creds. I think this is a mistake, considering the destructive nature of this method. I think we should make $creds required, so that the calling function has to be explicit about which database to destroy.

ergonlogic’s picture

Version: 6.x-2.0-rc2 » 6.x-2.x-dev
Status: Active » Fixed

Fixed in b16aaef by reloading the original site context.

See #2056577: Ensure we're deleting the proper database for a follow-up on my broader concerns.

ergonlogic’s picture

FileSize
431 bytes

For those running Aegir 2.0-rc2, here's a patch that fixes this issue, pending the release of RC3.

helmo’s picture

I think we should make $creds required, so that the calling function has to be explicit about which database to destroy.

Sounds like a good idea.

anarcat’s picture

looks good.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit b16aaef on dev-drupal-8, 6.x-2.x, dev-ssl-ip-allocation-refactor, 7.x-3.x, dev-subdir-multiserver, 6.x-2.x-backports, dev-helmo-3.x by ergonlogic:
    Issue #2055949: Fix migrate drops wrong database when domain name...