Skip to content

Commit

Permalink
add total size to relation information
Browse files Browse the repository at this point in the history
Total size inclused table data + indexes.
  • Loading branch information
chanmix51 committed Mar 15, 2017
1 parent ec6a7bf commit b43ac6b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
38 changes: 22 additions & 16 deletions sources/lib/Command/InspectRelation.php
Expand Up @@ -11,6 +11,7 @@

use PommProject\Cli\Exception\CliException;
use PommProject\Foundation\ConvertedResultIterator;
use PommProject\Foundation\Exception\SqlException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -29,8 +30,6 @@
*/
class InspectRelation extends RelationAwareCommand
{
protected $relation_oid;

/**
* configure
*
Expand All @@ -55,27 +54,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$this->relation = $input->getArgument('relation');
$this->relation_oid = $this->getSession()
->getInspector()
->getTableOid($this->schema, $this->relation)
$inspector = $this->getSession()
->getInspector('relation')
;

if ($this->relation_oid === null) {
try {
$relation_size = $inspector
->getTableTotalSizeOnDisk($this->schema, $this->relation);
} catch (SqlException $e) {
throw new CliException(
sprintf(
"Relation <comment>%s.%s</comment> not found.",
"Relation '%s.%s' not found.\nRelations in this schema are {%s}.",
$this->schema,
$this->relation
$this->relation,
join(', ', $inspector->getRelationsInSchema($this->schema)->slice('name'))
)
);
}

$fields_infos = $this->getSession()
->getInspector()
->getTableFieldInformation($this->relation_oid)
;
$fields_infos = $inspector->getTableFieldInformationName($this->schema, $this->relation);

$this->formatOutput($output, $fields_infos);
$this->formatOutput($output, $fields_infos, $relation_size);
}

/**
Expand All @@ -86,11 +84,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @access protected
* @param OutputInterface $output
* @param ConvertedResultIterator $fields_infos
* @param int $size
* @return void
*/
protected function formatOutput(OutputInterface $output, ConvertedResultIterator $fields_infos)
protected function formatOutput(OutputInterface $output, ConvertedResultIterator $fields_infos, $size)
{
$output->writeln(sprintf("Relation <fg=cyan>%s.%s</fg=cyan>", $this->schema, $this->relation));
$output->writeln(
sprintf(
"Relation <fg=cyan>%s.%s</fg=cyan> (size with indexes: %d bytes)",
$this->schema,
$this->relation,
$size
)
);
$table = (new Table($output))
->setHeaders(['pk', 'name', 'type', 'default', 'notnull', 'comment'])
;
Expand Down
2 changes: 1 addition & 1 deletion sources/lib/Command/InspectSchema.php
Expand Up @@ -69,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
->getSession()
->getInspector('relation')
->getRelationsInSchema($this->schema);
$this->formatOutput($output, $info, $schema_info);
$this->formatOutput($output, $info);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions sources/tests/Unit/Command/InspectRelation.php
Expand Up @@ -43,8 +43,7 @@ public function testExecute()
);
$this
->string($tester->getDisplay())
->isEqualTo(join(PHP_EOL, [
"Relation pomm_test.beta",
->contains(join(PHP_EOL, [
"+----+------------+--------------------------+--------------------------------------------------+---------+-------------------------------+",
"| pk | name | type | default | notnull | comment |",
"+----+------------+--------------------------+--------------------------------------------------+---------+-------------------------------+",
Expand All @@ -54,6 +53,7 @@ public function testExecute()
"+----+------------+--------------------------+--------------------------------------------------+---------+-------------------------------+",
"",
]))
->matches('#Relation pomm_test.beta \\(size with indexes\\: [0-9]+ bytes\\)#')
;
$this
->exception(function () use ($tester, $command) {
Expand Down

0 comments on commit b43ac6b

Please sign in to comment.