Skip to content

Commit

Permalink
Create drop table partition page
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Dec 1, 2020
1 parent b64be69 commit 0c38913
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
29 changes: 19 additions & 10 deletions libraries/classes/Controllers/Table/PartitionController.php
Expand Up @@ -78,23 +78,32 @@ public function check(): void

public function drop(): void
{
global $containerBuilder, $sql_query;

$partitionName = $_POST['partition_name'] ?? '';

if (strlen($partitionName) === 0) {
return;
}

$sql_query = sprintf(
'ALTER TABLE %s DROP PARTITION %s;',
Util::backquote($this->table),
Util::backquote($partitionName)
);
[$result, $query] = $this->model->drop($this->db, $this->table, $partitionName);

if ($result) {
$message = Generator::getMessage(
__('Your SQL query has been executed successfully.'),
$query,
'success'
);
} else {
$message = Generator::getMessage(
__('Error'),
$query,
'error'
);
}

/** @var SqlController $controller */
$controller = $containerBuilder->get(SqlController::class);
$controller->index();
$this->render('table/partition/drop', [
'partition_name' => $partitionName,
'message' => $message,
]);
}

public function optimize(): void
Expand Down
14 changes: 14 additions & 0 deletions libraries/classes/Table/Partition.php
Expand Up @@ -55,4 +55,18 @@ public function check(string $db, string $table, string $partition): array

return [$rows, $query];
}

public function drop(string $db, string $table, string $partition): array
{
$query = sprintf(
'ALTER TABLE %s DROP PARTITION %s;',
Util::backquote($table),
Util::backquote($partition)
);

$this->dbi->selectDb($db);
$result = $this->dbi->tryQuery($query);

return [(bool) $result, $query];
}
}
5 changes: 5 additions & 0 deletions templates/table/partition/drop.twig
@@ -0,0 +1,5 @@
<div class="container-fluid">
<h2>{% trans 'Drop partition' %}</h2>

{{ message|raw }}
</div>

0 comments on commit 0c38913

Please sign in to comment.