I used to be able to run 'drush sql-sync dev stage', but after the commit of http://drupal.org/node/683852 it produces the following error:

$ drush -d sql-sync dev stage
Found command: sql-sync (commandfile=sql) [0.17 sec, 3.77 MB]                                                                                     [bootstrap]
Including /usr/local/drush/commands/sql/sync.sql.inc [0.17 sec, 3.78 MB]                                                                          [bootstrap]
Undefined index:  uri [0.2 sec, 4.03 MB]                                                                                                             [notice]
Undefined index:  root [0.2 sec, 4.03 MB]                                                                                                            [notice]
Error: could not get database spec when it was required for dev
Drush command could not be completed. [0.2 sec, 4.03 MB]                                                                                          [error]

At first I thought I should change my drushrc.php, but this does not help. I even removed all the '%' variables from there - I still get the same error. Here is the last part from drushrc.php:

$ tail -n22 sites/default/drushrc.php 
$options['site-aliases']['stage'] = array(
    'uri' => 'default',
    'root' => '/home/yuval/work/example',
#    'db-url' => 'pgsql://username:password@dbhost.com:port/databasename',
    'remote-host' => 'yhager',
#    'remote-user' => 'publisher',
#    'path-aliases' => array(
#      '%drush' => '/drush/path/to/drush',
#      '%drush-script' => '/drush/path/to/drush/drush',
#      '%dump' => '/home/yuval/tmp/db.sql',
#      '%files' => 'sites/mydrupalsite.com/files',
#      '%custom' => '/my/custom/path',
#     ),
  );
$options['site-aliases']['dev'] = array(
    'uri' => 'default',
    'root' => '/home/yuval/work/example/www',
#    'path-aliases' => array(
#      '%dump' => '/home/yuval/tmp/example.sql',
#     ),
  );

using drush before this commit does not generate this error (thanks git bisect!), and it is still present in latest drush.

I am not sure if this is a misconfig on my end, or a bug though..

Comments

greg.1.anderson’s picture

Maybe you need to upgrade drush on your stage server? Drush gets the db spec from the remote site via:

drush stage sql-conf --all

Try to run that from the command line, and see if it produces reasonable output. If you define 'db-url' in your site alias, then drush will not need to fetch it via backend_invoke.

Anyway, while I do not quite remember, I think I might have made some change to drush that required both ends to be running the same version. Give that a try, and let me know if that does not solve your problem.

greg.1.anderson’s picture

Assigned: Unassigned » greg.1.anderson
Status: Active » Postponed (maintainer needs more info)
yhager’s picture

Status: Postponed (maintainer needs more info) » Active

I've set drush to be HEAD both on stage and dev.
Both drush stage sql-conf --all and drush dev sql-conf --all produce what looks to me quite reasonable (I've sanitized it a bit):

Array
(
    [default] => Array
        (
            [default] => Array
                (
                    [driver] => mysql
                    [username] => USERNAME
                    [password] => PASSWORD
                    [port] => 
                    [host] => localhost
                    [database] => DBNAME
                )

        )

)
greg.1.anderson’s picture

Status: Active » Postponed (maintainer needs more info)

Well, that is a head-scratcher. Make sure that you have #702554: Look up sitealias database settings only after a full database bootstrap, then run your sql-sync command again, this time with "-v -d" (verbose + debug), and post the result here.

moshe weitzman’s picture

fyi, -d implies -v. no advantage to sending them both.

yhager’s picture

Status: Postponed (maintainer needs more info) » Active

Yes, I have #702554: Look up sitealias database settings only after a full database bootstrap and I get the same thing.

I found something interesting though - I added var_dump($options); to the end of my drushrc.php, and found out it is not being read when I run drush sql-sync. If I simply run drush - I do get to see the dump.

Also, by chance, I found that whern I run drush dev sql-sync dev stage I do not get the error, but the standard message to make a backup. I have not continued this step though.

Hope this helps a bit in deciphering this.

I also have domain module installed, but using '--uri=site' does not help too. I tried disabling domain, and I still get the same behavior.

greg.1.anderson’s picture

Status: Active » Postponed (maintainer needs more info)

If you just run "drush" or "drush help", then drush will do a full bootstrap. If you do "drush sql-sync", drush will only bootstrap to the "bootstrap drush" level. If your drushrc.php is in your sites folder, then it will not be loaded unless you bootstrap at least to the "bootstrap site" level. If you want to define settings that can be used by sql-sync, put your drushrc in some location that is loaded right away, like $HOME/.drushrc.php or /etc/drushrc.php or drush/drushrc.php.

It would be useful to see the output of "drush -d sql-sync dev stage"; I don't have enough to go on yet.

greg.1.anderson’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.53 KB

Ah, wait, there actually was enough information to figure this one out; it came to me suddenly.

The issue is not that drush cannot get the db spec, but that it cannot find a definition for the alias at all. The reason it cannot find the alias is that said alias is defined in a site drushrc.php file that is not loaded. The bug is that the error message is wrong.

The enclosed patch corrects the error message.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

looks good.

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

yhager’s picture

Component: Code » Documentation
Status: Fixed » Active

Moving drushrc.php to $HOME/.drushrc.php indeed solved the issue.

I think this should be documented though. Currently, by reading the head of example.drushrc.php one just assumes that all these locations are equal (like sites/modules, sites/all/modules etc.) - and I can choose the one most convenient to me. Since I want to be able to use drush for other sites on the same machine, the sites folder looked like the best approach.
It is also not clear if $HOME/.drushrc.php can coexist with sites/default/drushrc.php in the sense that they can overwrite/complement each other (I can hold my site-aliases in my ~/.drushrc.php, but site specific data, like $options['l'] should go into sites/default/drushrc.php).

yhager’s picture

Title: Error: could not get database spec » Document the meaning of different locations for drushrc.php
greg.1.anderson’s picture

That is a good suggestion. In order to understand the difference between the site-specific configuration files and the others, you need to understand how drush bootstraping works, at least a little bit. Most of the drush configuration files are loaded during the 'drush' bootstrap, but the site-specific configuration file is not loaded until the 'site configuration' bootstrap phase. Some commands, like sql-sync, do not bootstrap past the drush bootstrap phase.

Another thing to note is that to a certain extent you got it backwards; the site folder is only used for the one drush site that the configuration file appears in. To have a config file used for all sites, you need to store it in one of the other possible locations. Also, $options['l'] selects which site drush should target, so this option in particular is useless in the context of a site-specific configuration file.

I'll add some more documentation to the example configuration file, but I want to get Moshe's opinion on #722612: Options for experimenting with drush bootstrap levels, and determining which configuration files were loaded. first.

greg.1.anderson’s picture

Status: Active » Needs review
StatusFileSize
new2.77 KB

The enclosed patch briefly describes bootstrapping in simplified form in an attempt to better explain the impact of storing drush configuration files in the different locations that are available.

moshe weitzman’s picture

Status: Needs review » Fixed

committed. thanks.

yhager’s picture

Thanks!

Status: Fixed » Closed (fixed)

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