diff --git a/sources/lib/Command/InspectRelation.php b/sources/lib/Command/InspectRelation.php index e6af094..0dca4b4 100644 --- a/sources/lib/Command/InspectRelation.php +++ b/sources/lib/Command/InspectRelation.php @@ -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; @@ -29,8 +30,6 @@ */ class InspectRelation extends RelationAwareCommand { - protected $relation_oid; - /** * configure * @@ -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 %s.%s 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); } /** @@ -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 %s.%s", $this->schema, $this->relation)); + $output->writeln( + sprintf( + "Relation %s.%s (size with indexes: %d bytes)", + $this->schema, + $this->relation, + $size + ) + ); $table = (new Table($output)) ->setHeaders(['pk', 'name', 'type', 'default', 'notnull', 'comment']) ; diff --git a/sources/lib/Command/InspectSchema.php b/sources/lib/Command/InspectSchema.php index dc749aa..025d704 100644 --- a/sources/lib/Command/InspectSchema.php +++ b/sources/lib/Command/InspectSchema.php @@ -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); } /** diff --git a/sources/tests/Unit/Command/InspectRelation.php b/sources/tests/Unit/Command/InspectRelation.php index 3e9147a..bb28d80 100644 --- a/sources/tests/Unit/Command/InspectRelation.php +++ b/sources/tests/Unit/Command/InspectRelation.php @@ -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 |", "+----+------------+--------------------------+--------------------------------------------------+---------+-------------------------------+", @@ -54,6 +53,7 @@ public function testExecute() "+----+------------+--------------------------+--------------------------------------------------+---------+-------------------------------+", "", ])) + ->matches('#Relation pomm_test.beta \\(size with indexes\\: [0-9]+ bytes\\)#') ; $this ->exception(function () use ($tester, $command) {