Skip to content

Commit

Permalink
add relation size in inspect:relations
Browse files Browse the repository at this point in the history
  • Loading branch information
chanmix51 committed Mar 15, 2017
1 parent 9c698c8 commit ec6a7bf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -30,7 +30,7 @@
}
},
"bin": ["bin/pomm.php"],
"minimum-stability": "dev",
"minimum-stability": "stable",
"extra": {
"branch-alias": {
"dev-master": "2.1-dev"
Expand Down
25 changes: 21 additions & 4 deletions sources/lib/Command/InspectSchema.php
Expand Up @@ -10,9 +10,11 @@
namespace PommProject\Cli\Command;

use PommProject\Foundation\ResultIterator;
use PommProject\Foundation\Where;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use PommProject\Cli\Exception\CliException;

/**
* InspectSchema
Expand Down Expand Up @@ -49,12 +51,25 @@ public function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$inspector = $this->getSession()->getInspector('schema');
$schema_info = $inspector
->getUserSchemas(new Where("n.nspname = $*", [$this->schema]))
->current();

if ($schema_info === null) {
throw new CliException(
sprintf(
"Could not find schema '%s'.\nAvailable schemas are {%s}",
$this->schema,
join(', ', $inspector->getUserSchemas()->slice('name'))
)
);
}
$info = $this
->getSession()
->getInspector()
->getSchemaRelations($this->fetchSchemaOid());
$this->formatOutput($output, $info);
->getInspector('relation')
->getRelationsInSchema($this->schema);
$this->formatOutput($output, $info, $schema_info);
}

/**
Expand All @@ -77,14 +92,16 @@ protected function formatOutput(OutputInterface $output, ResultIterator $info)
)
);
$table = (new Table($output))
->setHeaders(['name', 'type', 'oid ', 'comment'])
->setHeaders(['name', 'type', 'oid ', 'owner', 'size', 'comment'])
;

foreach ($info as $table_info) {
$table->addRow([
sprintf("<fg=yellow>%s</fg=yellow>", $table_info['name']),
$table_info['type'],
$table_info['oid'],
$table_info['owner'],
$table_info['size'],
wordwrap($table_info['comment'])
]);
}
Expand Down
1 change: 1 addition & 0 deletions sources/tests/Unit/Command/InspectSchema.php
Expand Up @@ -50,6 +50,7 @@ public function testExecute()
->contains("| beta | table")
->contains("This is the beta comment.")
->contains("| dingo | view")
->matches('#|\s+\w+\s+|\s+table\s+|\s+[0-9]+\s+|\s+\w+\s+|\s+[0-9]+ bytes\s+|#')
;

$inspector = new LegacyInspector;
Expand Down

0 comments on commit ec6a7bf

Please sign in to comment.