Skip to content

Commit

Permalink
Merge pull request #12 from howyi/add-partition
Browse files Browse the repository at this point in the history
Add partition
  • Loading branch information
howyi committed Sep 30, 2017
2 parents 9fe506a + 74de99b commit 816f08e
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Conv/Factory/TableStructureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ public static function fromTable(\PDO $pdo, string $dbName, string $tableName):
)
)->fetchAll();

$rawPartitionList = $pdo->query(
sprintf(
"SELECT * FROM information_schema.PARTITIONS WHERE table_schema = '%s' AND table_name = '%s' ORDER BY PARTITION_ORDINAL_POSITION ASC",
$dbName,
$tableName
)
)->fetchAll();

if (count($rawPartitionList) !== 1 and !is_null(reset($rawPartitionList)['PARTITION_METHOD'])) {
$methods = array_fill_keys(array_column($rawPartitionList, 'PARTITION_METHOD'), []);
foreach ($rawPartitionList as $item) {
$methods[$item['PARTITION_METHOD']][] = $item;
}
$groups = [];
foreach ($methods as $method => $methodValue) {
$expressions = array_fill_keys(array_column($methodValue, 'PARTITION_EXPRESSION'), []);
foreach ($methodValue as $value) {
$expressions[$value['PARTITION_EXPRESSION']][] = $value;
}
$groups[$method] = $expressions;
}
// dump($groups);
}


$columnStructureList = [];

foreach ($rawColumnList as $column) {
Expand Down
43 changes: 43 additions & 0 deletions src/Conv/Structure/PartitionPartStructure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Conv\Structure;

class PartitionPartStructure
{
private $name;
private $operator;
private $value;
private $engine;

/**
* @param string $name
* @param string $operator
* @param string $value
* @param string $engine
*/
public function __construct(
string $name,
string $operator,
string $value,
string $engine
) {
$this->name = $name;
$this->operator = $operator;
$this->value = $value;
$this->engine = $engine;
}

/**
* @return string
*/
public function getQuery(): string
{
return sprintf(
'PARTITION %s VALUES %s (%s) ENGINE = %s',
$this->name,
$this->operator,
$this->value,
$this->engine
);
}
}
29 changes: 29 additions & 0 deletions src/Conv/Structure/PartitionStructure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Conv\Structure;

class PartitionStructure
{
private $expression;
private $type;
private $nameOrder;
private $parts;

/**
* @param string $expression
* @param string $type
* @param string[] $nameOrder
* @param PartitionPartStructure[] $parts
*/
public function __construct(
string $expression,
string $type,
array $nameOrder,
array $parts
) {
$this->expression = $expression;
$this->type = $type;
$this->nameOrder = $nameOrder;
$this->parts = $parts;
}
}

0 comments on commit 816f08e

Please sign in to comment.