1) aborting install should return non zero exit code (so calling script can know it must stop)

2) when put in a shell script, drush seams to not be able to take term prompt

3) when providing a user and password not able to DROP/CREATE database, mysql yields :
ERROR 1044 (42000) at line 1: Access denied for user '****'@'localhost' to database '*****'
but drush proudly says install [ok] and stops ....

4) drush should provide a way to install drupal with a mysql user NOT allowed to DROP/CREATE database. ie with the user from the settings.php !!!!!

cheers

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moshe weitzman’s picture

Category: bug » support
Status: Active » Fixed

1) We handle user initiated abort in this script consistent with the rest of drush. Scripts usually don't have user interaction. See drush_user_abort()

3,4) drush tries to drop/create and if not possible, it tries to drop all tables instead. Typically the configured mysql user at least has that perm. If you are not seeing your tables get dropped, make sure the drupal mysql user has enough perms. Then reopen this issue.

xatoo’s picture

Status: Fixed » Needs review
FileSize
1.2 KB

I use site-install in a script as well.
Since the drupal database user has limited permissions I rather handle database creation by my own. Besides that I'd like my script to skip any confirmation.
In order to accomplish these things I applied the attached patch and then run drush site-install with the --no-db-create --yes options.

I also agree with point 1.

msonnabaum’s picture

Status: Needs review » Needs work

The "yes" option is unnecessary. You can already pass -y to it.

The current workflow of how the database is handled works, but I do think its a little silly to always try to drop it first. I too always use a more limited db user and seeing that error is annoying.

It seems like we could accomplish the same by checking if the db exists and then if so, drop all tables, if not, create it. I'm not convinced that the "no-db-create" option is useful.

quazardous’s picture

hi,

2) was a side effect of using piped commande... I ve found a workaround
3) is just a warning
4) ok it works ... was wrong

moshe weitzman’s picture

Title: site-install scripting » site-install - Never try to drop an existing database. Just drop tables.
Category: support » feature
Status: Needs work » Active

reframing the issue per #3

quazardous’s picture

and user abort should be able to return a non zero exit code : maybe with an option --error-on-abort

donquixote’s picture

I agree that we should assume that this is all run with a limited-access user.
For me it says
ERROR 1044 (42000) at line 1: Access denied for user 'xxx'@'localhost' to database 'xxx'
which is only because of the DROP DATABASE.
Showing an error is just too strong a statement.

laurentchardin’s picture

There's one use-case when you don't want to drop the database : execute multiple site-install at once, using --db-prefix so you can store all tables in the same database (yes, i had this once).

Since site-install drops the DB, you cannot script a multiple drupal instances installation procedure.

Agileware’s picture

Subscribe

Patch #2 worksforme2

hass’s picture

Droping DB is no good idea as user may not have permission to recreate and multisites (not yet tested myself) seems a real problem here.

Anonymous’s picture

was looking into this, because i'm getting warnings even with a user that can create/drop the site db.

but, my user doesn't have the rights to do this in drush_sql_build_createdb_sql():

      $sql[] = sprintf('GRANT ALL PRIVILEGES ON %s.* TO \'%s\'@\'%s\'', $dbname, $db_spec['username'], $db_spec['host

so, that needs to die. not sure if that handles the case where a user for the site doesn't have drop/create privileges, but that line has to go.

moshe weitzman’s picture

Version: 7.x-4.4 »

#3 makes sense, but there is no platform independent way to check if a given DB exists. So we need implementations for mysql, postgres, sqlite, and sqlsrv.

greg.1.anderson’s picture

Assigned: Unassigned » greg.1.anderson

#11: The grant command should only happen if the db is created.

#12: We could use the drush sql-query wrapper to try to contact the db; that way, the db-specific implementations are already provided.

I should fix all of this sql stuff at the sprint.

Anonymous’s picture

re #13 - IMHO, the grant stuff should only happen if its explicitly asked for.

donquixote’s picture

#14
makes sense. add an option to create the db (if not exists), and otherwise assume that a db already exists.
Maybe even add another option to delete tables (if applies), and otherwise stop if the db is found to be not empty?

greg.1.anderson’s picture

Maybe "ALL PRIVILEGES" is too much for some users, but if you have no grant statement, then the db will not work until some privs are granted by hand. I therefore think that at least some privs should be granted; otherwise the create option is not too useful. If we do not have a mechanism to specify the exact permissions desired, "all" is okay for a dev machine. If you don't want "all", you can create the db and set the privs by hand, and then skip the --create-db option. A patch to select the desired permission level would be welcome, though.

moshe weitzman’s picture

I will try to get to this

moshe weitzman’s picture

Status: Active » Needs work
FileSize
4.13 KB

The good news is that I got pretty far on this. See patch.

The bad news is that my approach needs tweaking. On mysql at least, a limited privilege user can't query INFORMATION_SCHEMA as that requires 'Show Databases' perm. When regular user does that, mysql return NULL and success exit code. This response is indistinguishable from a permissioned user requesting a non-existent DB. Ugh.

greg.1.anderson’s picture

With a bit of refactoring, you could use _drush_sql_query to run a "show tables;" query. If you got back zero rows, then do nothing (empty db is good to go); one or more rows, call sql_drop. If there is no database, then the sql connect should return an error, and you can then call sql_create.

Didn't have time to try that, but I would think that would work.

moshe weitzman’s picture

Assigned: moshe weitzman » Unassigned

Someone else will have to push this along.

greg.1.anderson’s picture

Assigned: Unassigned » greg.1.anderson

I'll add it to my queue, but it may be a while. Anyone else who wants to jump in with a patch should feel free.

moshe weitzman’s picture

Assigned: greg.1.anderson » msonnabaum
Status: Needs work » Patch (to be ported)

I managed to fix drush_sql_db_exists() for mysql so committed to master.

I am seeing all tests pass except for one unrelated fail in completeTest (@dev/@stage confusion).

I'd like to backport this in 4.6 (we are at 4.5RC right now).

clemens.tolboom’s picture

moshe weitzman’s picture

Status: Patch (to be ported) » Fixed

I guess backport isn't really necessary. Lets call this fixed and work on the #23 bug elsewhere.

Status: Fixed » Closed (fixed)

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