Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate DB availability during blt:site:install w/o using drush #2814

Closed
bkosborne opened this issue May 10, 2018 · 5 comments
Closed

Validate DB availability during blt:site:install w/o using drush #2814

bkosborne opened this issue May 10, 2018 · 5 comments
Labels
Enhancement A feature or feature request Support A support request

Comments

@bkosborne
Copy link
Contributor

I'm trying to write some basic on-boarding instructions for developers on my team for a project that uses BLT.

We're using a docker environment. Once the environment is setup, the database server is running, but the default database doesn't exist yet.

I want to instruct users to run the blt drupal:install command, which runs the drush site-install command to install the site. Drush is smart enough to automatically create the database if it detects that it doesn't exist, which is great.

However, BLT doesn't let drush get that far, because the internal:drupal:install command runs the validateMySqlAvailable validation hook. This hook verifies that the MySQL database is available by running drush sqlq "SHOW DATABASES", which fails because drush is trying to connect to a MySQL database that doesn't yet exist.

I'd like to suggest a different method to be used to verify if MySQL is available or not, one that just checks that a connection can be made to the server, but not attempt to connect to the database, since it may not exist yet.

Alternatively, is there a way I can just remove that validation hook? I already provide my own replacement version of internal:drupal:install command, but since the hooks are annotations on the original class, I don't think I can remove them.

Or maybe I can add a pre-hook that checks if the database doesn't exist, and just create it if not...

@bkosborne
Copy link
Contributor Author

bkosborne commented May 10, 2018

For now I got around this with this:

<?php

namespace Acquia\Blt\Custom\Hooks;

use Acquia\Blt\Robo\BltTasks;
use Symfony\Component\Console\Event\ConsoleCommandEvent;

/**
 * Make sure database exists before drupal:install is run.
 *
 * See https://github.com/acquia/blt/issues/2814 for why this is needed.
 */
class CreateDatabaseBeforeInstallCommandHook extends BltTasks {

  /**
   * @hook command-event drupal:install
   */
  public function preDrupalInstall(ConsoleCommandEvent $event) {
    $this->say('Dropping & recreating database');
    $this->taskExec('mysql -u root -h db -e "DROP DATABASE IF EXISTS drupal"')->run();
    $this->taskExec('mysql -u root -h db -e "CREATE DATABASE drupal /*!40100 DEFAULT CHARACTER SET utf8mb4 */;"')->run();
  }

}

@mikemadison13
Copy link
Contributor

is the issue here that the Docker setup process doesn't create the database (where perhaps the Vagrant / Drupal VM process does) so our checks fail as a result?

@japerry did you run into something similar on this with Docksal?

@ba66e77 ba66e77 added Enhancement A feature or feature request Support A support request labels May 31, 2018
@lcatlett
Copy link
Contributor

This bug was fixed in #2997 but the revert in #3028 re-introduced it. This will block running drupal:install locally and on Acquia without human interaction until the fix in #2997 is re-merged or another approach is implemented.

@bkosborne
Copy link
Contributor Author

Your commit here (18aab15) should fix this issue. I can't quite figure out if that commit has been merged into 9.x or 10.x?

@mikemadison13
Copy link
Contributor

closing due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement A feature or feature request Support A support request
Projects
None yet
Development

No branches or pull requests

4 participants