Skip to content

Commit

Permalink
Merge pull request #7972 from kenjis/feat-spark-db-table-show-db-config
Browse files Browse the repository at this point in the history
feat: db:table shows db config
  • Loading branch information
kenjis committed Oct 12, 2023
2 parents a8f589d + 3680360 commit bfeb6c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions system/Commands/Database/ShowTableInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function run(array $params)
$this->db = Database::connect();
$this->DBPrefix = $this->db->getPrefix();

$this->showDBConfig();

$tables = $this->db->listTables();

if (array_key_exists('desc', $params)) {
Expand Down Expand Up @@ -145,6 +147,22 @@ public function run(array $params)
$this->showDataOfTable($tableName, $limitRows, $limitFieldValue);
}

private function showDBConfig(): void
{
$data = [[
'hostname' => $this->db->hostname,
'database' => $this->db->getDatabase(),
'username' => $this->db->username,
'DBDriver' => $this->db->getPlatform(),
'DBPrefix' => $this->DBPrefix,
'port' => $this->db->port,
]];
CLI::table(
$data,
['hostname', 'database', 'username', 'DBDriver', 'DBPrefix', 'port']
);
}

private function removeDBPrefix(): void
{
$this->db->setPrefix('');
Expand Down
1 change: 1 addition & 0 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* @property int $transDepth
* @property bool $transFailure
* @property bool $transStatus
* @property string $username
*
* @template TConnection
* @template TResult
Expand Down
10 changes: 10 additions & 0 deletions tests/system/Commands/Database/ShowTableInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public function testDbTable(): void
$this->assertMatchesRegularExpression($expectedPattern, $result);
}

public function testDbTableShowsDBConfig(): void
{
command('db:table');

$result = $this->getNormalizedResult();

$expectedPattern = '/\| hostname[[:blank:]]+\| database[[:blank:]]+\| username[[:blank:]]+\| DBDriver[[:blank:]]+\| DBPrefix[[:blank:]]+\| port[[:blank:]]+\|/';
$this->assertMatchesRegularExpression($expectedPattern, $result);
}

public function testDbTableShow(): void
{
command('db:table --show');
Expand Down

0 comments on commit bfeb6c5

Please sign in to comment.