Changes Dbal\DatabaseName, Dbal\TableName and Triggers\TriggerName to implements the new Identifier\Identifier interface. Moves Dbal\DatabaseName, Dbal\TableName and Triggers\TriggerName to the Identifiers namespace. Renames the tryFromValue() and fromValue() methods to just tryFrom() and from() respectively. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
151 lines
3.8 KiB
PHP
151 lines
3.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpMyAdmin\Partitioning;
|
|
|
|
use PhpMyAdmin\DatabaseInterface;
|
|
use PhpMyAdmin\Identifiers\DatabaseName;
|
|
use PhpMyAdmin\Identifiers\TableName;
|
|
use PhpMyAdmin\Util;
|
|
|
|
use function sprintf;
|
|
|
|
final class Maintenance
|
|
{
|
|
public function __construct(private DatabaseInterface $dbi)
|
|
{
|
|
}
|
|
|
|
/** @return mixed[] */
|
|
public function analyze(DatabaseName $db, TableName $table, string $partition): array
|
|
{
|
|
$query = sprintf(
|
|
'ALTER TABLE %s ANALYZE PARTITION %s;',
|
|
Util::backquote($table->getName()),
|
|
Util::backquote($partition),
|
|
);
|
|
|
|
$this->dbi->selectDb($db);
|
|
$result = $this->dbi->fetchResult($query);
|
|
|
|
$rows = [];
|
|
foreach ($result as $row) {
|
|
$rows[$row['Table']][] = $row;
|
|
}
|
|
|
|
return [$rows, $query];
|
|
}
|
|
|
|
/** @return mixed[] */
|
|
public function check(DatabaseName $db, TableName $table, string $partition): array
|
|
{
|
|
$query = sprintf(
|
|
'ALTER TABLE %s CHECK PARTITION %s;',
|
|
Util::backquote($table->getName()),
|
|
Util::backquote($partition),
|
|
);
|
|
|
|
$this->dbi->selectDb($db);
|
|
$result = $this->dbi->fetchResult($query);
|
|
|
|
$rows = [];
|
|
foreach ($result as $row) {
|
|
$rows[$row['Table']][] = $row;
|
|
}
|
|
|
|
return [$rows, $query];
|
|
}
|
|
|
|
/** @return mixed[] */
|
|
public function drop(DatabaseName $db, TableName $table, string $partition): array
|
|
{
|
|
$query = sprintf(
|
|
'ALTER TABLE %s DROP PARTITION %s;',
|
|
Util::backquote($table->getName()),
|
|
Util::backquote($partition),
|
|
);
|
|
|
|
$this->dbi->selectDb($db);
|
|
$result = $this->dbi->tryQuery($query);
|
|
|
|
return [(bool) $result, $query];
|
|
}
|
|
|
|
/** @return mixed[] */
|
|
public function optimize(DatabaseName $db, TableName $table, string $partition): array
|
|
{
|
|
$query = sprintf(
|
|
'ALTER TABLE %s OPTIMIZE PARTITION %s;',
|
|
Util::backquote($table->getName()),
|
|
Util::backquote($partition),
|
|
);
|
|
|
|
$this->dbi->selectDb($db);
|
|
$result = $this->dbi->fetchResult($query);
|
|
|
|
$rows = [];
|
|
foreach ($result as $row) {
|
|
$rows[$row['Table']][] = $row;
|
|
}
|
|
|
|
return [$rows, $query];
|
|
}
|
|
|
|
/**
|
|
* @return array<int, bool|string>
|
|
* @psalm-return array{bool, string}
|
|
*/
|
|
public function rebuild(DatabaseName $db, TableName $table, string $partition): array
|
|
{
|
|
$query = sprintf(
|
|
'ALTER TABLE %s REBUILD PARTITION %s;',
|
|
Util::backquote($table->getName()),
|
|
Util::backquote($partition),
|
|
);
|
|
|
|
$this->dbi->selectDb($db);
|
|
$result = $this->dbi->tryQuery($query);
|
|
|
|
return [(bool) $result, $query];
|
|
}
|
|
|
|
/** @return mixed[] */
|
|
public function repair(DatabaseName $db, TableName $table, string $partition): array
|
|
{
|
|
$query = sprintf(
|
|
'ALTER TABLE %s REPAIR PARTITION %s;',
|
|
Util::backquote($table->getName()),
|
|
Util::backquote($partition),
|
|
);
|
|
|
|
$this->dbi->selectDb($db);
|
|
$result = $this->dbi->fetchResult($query);
|
|
|
|
$rows = [];
|
|
foreach ($result as $row) {
|
|
$rows[$row['Table']][] = $row;
|
|
}
|
|
|
|
return [$rows, $query];
|
|
}
|
|
|
|
/**
|
|
* @return array<int, bool|string>
|
|
* @psalm-return array{bool, string}
|
|
*/
|
|
public function truncate(DatabaseName $db, TableName $table, string $partition): array
|
|
{
|
|
$query = sprintf(
|
|
'ALTER TABLE %s TRUNCATE PARTITION %s;',
|
|
Util::backquote($table->getName()),
|
|
Util::backquote($partition),
|
|
);
|
|
|
|
$this->dbi->selectDb($db);
|
|
$result = $this->dbi->tryQuery($query);
|
|
|
|
return [(bool) $result, $query];
|
|
}
|
|
}
|