Problem/Motivation

When you try to reinstall the Drupal site using the config there is warning.

 You are about to:
 * DROP all tables in your 'db_test' database.

 ┌ Do you want to continue? Yes

 [warning] Failed to drop or create the database. Do it yourself before installing. ERROR 1051 (42S02) at line 1: Unknown table 'db_test.sv_user_notes'

 [notice] Starting Drupal installation. This takes a while.

Steps to reproduce

Fresh re-install of a drupal site using the existing configuration.

Proposed resolution

MySQL permissions are good.

mysql> SHOW GRANTS FOR 'dbuser_test'@'%'\G;
*************************** 1. row ***************************
Grants for dbuser_test@%: GRANT USAGE ON *.* TO `dbuser_test`@`%`
*************************** 3. row ***************************
Grants for dbuser_test@%: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, CREATE VIEW, SHOW VIEW ON `db_test`.* TO `dbuser_test`@`%`

Remaining tasks

User interface changes

API changes

Data model changes

Comments

emilorol created an issue.

chi’s picture

Looks like core bug. It does not distinguish tables and views. I typically drop the database manually before reinstalling site.

emilorol’s picture

I think we can add a drop command similar to the rebuild command.

emilorol’s picture

<?php

declare(strict_types=1);

namespace Drupal\sql_views\Command;

use Drupal\Core\Database\Connection;
use Drupal\sql_views\SqlViewPluginManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 * {@selfdoc}
 */
#[AsCommand(
  name: 'sql:views:delete',
  description: 'Delete SQL views',
)]
final class DeleteCommand extends Command {

  /**
   * {@inheritdoc}
   */
  public function __construct(
    private readonly Connection $database,
    private readonly SqlViewPluginManager $viewManager,
  ) {
    parent::__construct();
  }

  /**
   * {@inheritdoc}
   */
  protected function execute(InputInterface $input, OutputInterface $output): int {
    // Drop all SQL views.
    foreach ($this->viewManager->getSupportedDefinitions() as $plugin_id => $definition) {
      $this->viewManager->uninstallView($plugin_id);
    }
    (new SymfonyStyle($input, $output))->success('Dropped all SQL views');
    return self::SUCCESS;
  }

}

?>
chi’s picture

Looks good. Patches are welcome.

emilorol’s picture

I will do that