drush sql-sync @live @localdev

The above command runs fine. However, when I add the --santiize flag, I get the following error:

The following post-sync operations will be done on the destination:
* Reset passwords and email addresses in user table
* Truncate Drupal's sessions table

ERROR 1146 (42S02) at line 1: Table 'mydbname.users' doesn't exist

Here's the relevant part of my aliases config for this environment:

$aliases['localdev'] = array(
  ...
  'databases' => array(
    'default' => array(
      'default' => array(
        'database' => 'mydbname',
        'username' => 'myusername',
        'password' => 'mypassword',
        'host' => 'localhost',
        'port' => '',
        'driver' => 'mysql',
        'prefix' => 'd_',
      )
    )
  )
);

I confirmed the import without --sanitize is using the prefix as expected.

Here's the related code in drush/commands/sql/sync.sql.inc. Note when I manually hardcode the prefix in this query, it works. The second session query will also error out unless hard coded.

127   if (!empty($user_table_updates)) {
128     $sanitize_query = "UPDATE users SET " . implode(', ', $user_table_updates) . " WHERE uid > 0;";
129     drush_sql_register_post_sync_op('user-email', dt('Reset !message in user table', array('!message' => implode(' and ', $mes    sage_list))), $sanitize_query);
130   }
131 
132   // Seems quite portable (SQLite?) - http://en.wikipedia.org/wiki/Truncate_(SQL)
133   $sql_sessions = 'TRUNCATE TABLE sessions;';
134   drush_sql_register_post_sync_op('sessions', dt('Truncate Drupal\'s sessions table'), $sql_sessions);

I did try wrapping the tables in {}, but it did not work.

Comments

djdevin’s picture

Version: 7.x-5.4 » 7.x-5.8

Still an issue in 5.8.

There was a ticket about how table prefixes don't work in sqlq, but I can't find it...

greg.1.anderson’s picture

Version: 7.x-5.8 » 8.x-6.x-dev
Status: Active » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If desired, you may copy this bug to our Github project and then post a link here to the new issue. Please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.