From c785f5789b4291a7164fe2832c005bf0aca06932 Mon Sep 17 00:00:00 2001 From: Ruchit Patel Date: Tue, 23 Jul 2024 13:25:09 +0530 Subject: [PATCH 1/7] WIP: Add functions for pgsql. --- config/db-auditor.php | 6 ++ src/Commands/DBAuditCommand.php | 1 + src/Commands/DBSummaryCommand.php | 18 ++++- src/Constants/Constant.php | 2 + src/Queries/DatabaseCharacterSetClass.php | 8 ++ src/Queries/DatabaseEngineClass.php | 6 ++ src/Queries/DatabaseSizeClass.php | 15 ++++ src/Queries/DatabaseTableClass.php | 11 ++- src/Traits/DBFunctions.php | 4 +- src/views/postgresql/constraint.blade.php | 62 ++++++++++++++++ src/views/postgresql/standard.blade.php | 35 +++++++++ src/views/postgresql/table_standard.blade.php | 74 +++++++++++++++++++ 12 files changed, 238 insertions(+), 4 deletions(-) create mode 100644 src/views/postgresql/constraint.blade.php create mode 100644 src/views/postgresql/standard.blade.php create mode 100644 src/views/postgresql/table_standard.blade.php diff --git a/config/db-auditor.php b/config/db-auditor.php index e0de1f7..a2e7a5b 100644 --- a/config/db-auditor.php +++ b/config/db-auditor.php @@ -27,5 +27,11 @@ Constant::CONSTRAINT_COMMAND, Constant::SUMMARY_COMMAND, Constant::TRACK_COMMAND, + ], + 'postgresql_commands' => [ + Constant::STANDARD_COMMAND, + Constant::CONSTRAINT_COMMAND, + Constant::SUMMARY_COMMAND, + Constant::TRACK_COMMAND, ] ]; diff --git a/src/Commands/DBAuditCommand.php b/src/Commands/DBAuditCommand.php index 0545f7f..3687fad 100644 --- a/src/Commands/DBAuditCommand.php +++ b/src/Commands/DBAuditCommand.php @@ -31,6 +31,7 @@ public function handle(): void $commands = match (connection_driver()) { Constant::SQLITE_DB => config('db-auditor.sqlite_commands'), Constant::MYSQL_DB => config('db-auditor.mysql_commands'), + Constant::POSTGRESQL_DB => config('db-auditor.postgresql_commands'), }; $commandSelect = select( diff --git a/src/Commands/DBSummaryCommand.php b/src/Commands/DBSummaryCommand.php index b3df694..edf823d 100644 --- a/src/Commands/DBSummaryCommand.php +++ b/src/Commands/DBSummaryCommand.php @@ -33,6 +33,7 @@ public function handle() { return match (connection_driver()) { 'sqlite' => $this->sqlite(), + 'pgsql' => $this->pgsql(), default => $this->mysql(), }; } @@ -72,7 +73,7 @@ public function sqlite(): int public function mysql(): int { $this->table( - ['Database Name', 'Size', 'Table Count', 'Engin', 'Character Set'], + ['Database Name', 'Size', 'Table Count', 'DB Version', 'Character Set'], [[ database_name(), $this->getDatabaseSize(), @@ -84,4 +85,19 @@ public function mysql(): int return self::SUCCESS; } + + public function pgsql(): int + { + $this->table( + ['Database Name', 'Size', 'Table Count', 'Character Set'], + [[ + database_name(), + $this->getDatabaseSize(), + $this->getTableList(), + $this->getCharacterSetName(), + ]] + ); + + return self::SUCCESS; + } } diff --git a/src/Constants/Constant.php b/src/Constants/Constant.php index 1327060..3efa562 100644 --- a/src/Constants/Constant.php +++ b/src/Constants/Constant.php @@ -36,6 +36,8 @@ class Constant public const SQLITE_DB = 'sqlite'; + public const POSTGRESQL_DB = 'pgsql'; + public const UNIQUE_RULES = 'unique'; public const INDEX_FILE_NAME = 'update_table_index.php'; diff --git a/src/Queries/DatabaseCharacterSetClass.php b/src/Queries/DatabaseCharacterSetClass.php index 5aa76f2..0ed9ec0 100644 --- a/src/Queries/DatabaseCharacterSetClass.php +++ b/src/Queries/DatabaseCharacterSetClass.php @@ -19,6 +19,7 @@ public function __invoke(): string { return match ($this->driver) { 'sqlite' => $this->sqlite(), + 'pgsql' => $this->pgsql(), default => $this->mysql(), }; } @@ -45,4 +46,11 @@ public function select($query): array { return DB::select($query); } + + public function pgsql(): string + { + $result = $this->select("SELECT pg_encoding_to_char(encoding) AS character_set FROM pg_database WHERE datname = current_database();"); + + return reset($result)?->character_set ?? Constant::DASH; + } } diff --git a/src/Queries/DatabaseEngineClass.php b/src/Queries/DatabaseEngineClass.php index a56d5f9..255ebbe 100644 --- a/src/Queries/DatabaseEngineClass.php +++ b/src/Queries/DatabaseEngineClass.php @@ -17,6 +17,7 @@ public function __invoke(): string { return match ($this->driver) { 'sqlite' => $this->sqlite(), + 'pgsql' => $this->pgsql(), default => $this->mysql(), }; } @@ -43,4 +44,9 @@ public function select($query): array { return DB::select($query); } + + public function pgsql(): string + { + + } } diff --git a/src/Queries/DatabaseSizeClass.php b/src/Queries/DatabaseSizeClass.php index 4be721d..cb4e977 100644 --- a/src/Queries/DatabaseSizeClass.php +++ b/src/Queries/DatabaseSizeClass.php @@ -20,6 +20,7 @@ public function __invoke(): string { return match ($this->driver) { 'sqlite' => $this->sqlite(), + 'pgsql' => $this->pgsql(), default => $this->mysql(), }; } @@ -57,5 +58,19 @@ public function mysql(): string } + /** + * pgsql size + * + * @return string + */ + public function pgsql(): string + { + $result = collect( + $this->select("SELECT pg_size_pretty( pg_database_size('".$this->database."') );") + )->toArray(); + + return reset($result)->pg_size_pretty ?? Constant::DASH; + } + } diff --git a/src/Queries/DatabaseTableClass.php b/src/Queries/DatabaseTableClass.php index 81a1d16..c9f0e0e 100644 --- a/src/Queries/DatabaseTableClass.php +++ b/src/Queries/DatabaseTableClass.php @@ -13,10 +13,11 @@ public function __construct() $this->driver = connection_driver(); } - public function __invoke(): array + public function __invoke(): array|string|int { return match ($this->driver) { 'sqlite' => $this->sqlite(), + 'pgsql' => $this->pgsql(), default => $this->mysql(), }; } @@ -49,4 +50,12 @@ public function mysql(): array 'Tables_in_'.database_name() ); } + + public function pgsql() : int + { + return collect(array_column( + $this->select("SELECT count(*) AS table_count FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema';"), + 'table_count' + ))->first(); + } } diff --git a/src/Traits/DBFunctions.php b/src/Traits/DBFunctions.php index 0c6ec0d..0c8358e 100644 --- a/src/Traits/DBFunctions.php +++ b/src/Traits/DBFunctions.php @@ -50,9 +50,9 @@ public function checkTableExist(string $tableName): bool /** * Get Table List - * @return array + * @return array|string|int */ - public function getTableList(): array + public function getTableList(): array|string|int { $tableList = new DatabaseTableClass(); return $tableList(); diff --git a/src/views/postgresql/constraint.blade.php b/src/views/postgresql/constraint.blade.php new file mode 100644 index 0000000..ed72ea1 --- /dev/null +++ b/src/views/postgresql/constraint.blade.php @@ -0,0 +1,62 @@ +
+
+ TABLE NAME : {{ $data['table'] }} +
+ +
+ Columns + + {{ $data['field_count'] }} +
+ +
+ Table Size + + {{ $data['size'] }} +
+ +
+
+ Fields + + Data Type +
+ + @foreach ($data['fields'] as $field) +
+ {{ $field->COLUMN_NAME }} + {{ $field->COLUMN_TYPE }} + + {{ $field->DATA_TYPE }} +
+ @endforeach +
+ +
+ + @foreach ($data['constraint'] as $key => $value) + @if ($value) +
+ {{ strtoupper($key) }} +
+ @foreach ($value as $constraintField) + + @if ($key === 'foreign') +
+ {{ $constraintField['column_name'] }} + + {{ $constraintField['foreign_table_name'] }} + {{ $constraintField['foreign_column_name'] }} +
+ @else +
+ {{ $constraintField }} + +
+ @endif + @endforeach + @endif + @endforeach +
+
diff --git a/src/views/postgresql/standard.blade.php b/src/views/postgresql/standard.blade.php new file mode 100644 index 0000000..7782d07 --- /dev/null +++ b/src/views/postgresql/standard.blade.php @@ -0,0 +1,35 @@ +
+ @php + $success = 0; + $error = 0; + @endphp +
+
+ TABLE NAME + + Standardization +
+ @foreach ($tableStatus as $table) +
+ {{ $table['name'] }} + ({{ $table['size'] }} MB) + + @if ($table['status']) + @php $success++; @endphp + + @else + @php $error++; @endphp + + @endif +
+ @endforeach +
+ {{ $success }} TABLE + PASSED ✓ +
+
+ {{ $error }} TABLE + FAILED ✗ +
+
+
diff --git a/src/views/postgresql/table_standard.blade.php b/src/views/postgresql/table_standard.blade.php new file mode 100644 index 0000000..419042f --- /dev/null +++ b/src/views/postgresql/table_standard.blade.php @@ -0,0 +1,74 @@ +
+ TABLE NAME : {{ str_replace('_', ' ', $tableStatus['table']) }} + + @if ($tableStatus['table_comment']) +
+ suggestion(s) +
+
    + @foreach ($tableStatus['table_comment'] as $commentKey => $comment) +
  1. + {{ $comment }} +
  2. + @endforeach +
+ @endif +
+ + + + + + + + + + + + @foreach ($tableStatus['fields'] as $key => $field) + + @if (!empty($field)) + @if ((isset($field['suggestion']) && isset($field['datatype']) && count($field) === 2) || count($field) === 1) + + + @else + + + @endif + + + + @php + if(isset($field['datatype'])) { + unset($field['datatype']); + } + @endphp + @foreach ($field as $key => $fieldComment) + + + + + + @if ($key === 'suggestion') + + @else + + @endif + + @endforeach + @else + + + + + + @endif + + @php + unset($field['datatype']); + @endphp + @endforeach + +
field name standard check datatype size suggestion(s)
{{ $key }}{{ $key }} {{ $field['datatype']['data_type'] ?? "-" }} {{ $field['datatype']['size'] ?? "-" }}
{{ $fieldComment }} {{ $fieldComment }}
{{ $key }} {{ $field['datatype']['data_type'] ?? "-" }} {{ $field['datatype']['size'] ?? "-" }} -
+
+
From 31b603dacdb1af5a2d793d3db9fb7c53adb71953 Mon Sep 17 00:00:00 2001 From: Ruchit Patel Date: Wed, 24 Jul 2024 14:24:15 +0530 Subject: [PATCH 2/7] Integrate postgresql functions for db standard. --- src/Commands/DBStandardCommand.php | 4 +- src/Commands/DBSummaryCommand.php | 2 +- src/Queries/DatabaseTableClass.php | 12 +++--- src/Queries/DatabaseTableFieldTypeClass.php | 38 ++++++++++++++++++- src/Queries/DatabaseTableFieldsClass.php | 15 ++++++++ src/Queries/DatabaseTableSizeClass.php | 7 ++++ src/Traits/DBFunctions.php | 2 +- src/Traits/Rules.php | 6 ++- .../constraint.blade.php | 0 .../{postgresql => pgsql}/standard.blade.php | 0 .../table_standard.blade.php | 0 11 files changed, 73 insertions(+), 13 deletions(-) rename src/views/{postgresql => pgsql}/constraint.blade.php (100%) rename src/views/{postgresql => pgsql}/standard.blade.php (100%) rename src/views/{postgresql => pgsql}/table_standard.blade.php (100%) diff --git a/src/Commands/DBStandardCommand.php b/src/Commands/DBStandardCommand.php index 36f987f..aebd55d 100644 --- a/src/Commands/DBStandardCommand.php +++ b/src/Commands/DBStandardCommand.php @@ -91,8 +91,8 @@ public function tableReport(string $tableName, string $connection) if (!$tableStatus) { return render(view('DBAuditor::error_message', ['message' => 'No Table Found'])); - } else { - render(view('DBAuditor::'.$connection.'.table_standard', ['tableStatus' => $tableStatus])); } + + render(view('DBAuditor::'.$connection.'.table_standard', ['tableStatus' => $tableStatus])); } } diff --git a/src/Commands/DBSummaryCommand.php b/src/Commands/DBSummaryCommand.php index edf823d..1b1139a 100644 --- a/src/Commands/DBSummaryCommand.php +++ b/src/Commands/DBSummaryCommand.php @@ -93,7 +93,7 @@ public function pgsql(): int [[ database_name(), $this->getDatabaseSize(), - $this->getTableList(), + count($this->getTableList()), $this->getCharacterSetName(), ]] ); diff --git a/src/Queries/DatabaseTableClass.php b/src/Queries/DatabaseTableClass.php index c9f0e0e..5779349 100644 --- a/src/Queries/DatabaseTableClass.php +++ b/src/Queries/DatabaseTableClass.php @@ -13,7 +13,7 @@ public function __construct() $this->driver = connection_driver(); } - public function __invoke(): array|string|int + public function __invoke(): array { return match ($this->driver) { 'sqlite' => $this->sqlite(), @@ -51,11 +51,11 @@ public function mysql(): array ); } - public function pgsql() : int + public function pgsql() : array { - return collect(array_column( - $this->select("SELECT count(*) AS table_count FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema';"), - 'table_count' - ))->first(); + return array_column( + $this->select("SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';"), + 'table_name' + ); } } diff --git a/src/Queries/DatabaseTableFieldTypeClass.php b/src/Queries/DatabaseTableFieldTypeClass.php index 2064856..026889a 100644 --- a/src/Queries/DatabaseTableFieldTypeClass.php +++ b/src/Queries/DatabaseTableFieldTypeClass.php @@ -20,6 +20,7 @@ public function __invoke(): array { return match ($this->driver) { 'sqlite' => $this->sqlite(), + 'pgsql' => $this->pgsql(), default => $this->mysql(), }; } @@ -57,7 +58,7 @@ public function mysql(): array $dataType = reset($data); - if(in_array($dataType->DATA_TYPE, Constant::NUMERIC_DATATYPE)) { + if (in_array($dataType->DATA_TYPE, Constant::NUMERIC_DATATYPE)) { if($dataType->DATA_TYPE === Constant::DATATYPE_DECIMAL) { $size = "(". $dataType->NUMERIC_PRECISION .",". $dataType->NUMERIC_SCALE .")"; @@ -72,4 +73,39 @@ public function mysql(): array return ['data_type' => $dataType->DATA_TYPE, 'size' => $size]; } } + + public function pgsql(): array + { + $data = DB::select("SELECT + column_name, + CASE + WHEN data_type = 'character varying' THEN 'varchar' + WHEN data_type = 'character' THEN 'char' + WHEN data_type = 'timestamp without time zone' THEN 'timestamp' + ELSE data_type + END AS data_type, + character_maximum_length, + is_nullable, + CASE + WHEN data_type IN ('character varying', 'character') THEN character_maximum_length + WHEN data_type IN ('numeric', 'decimal') THEN numeric_precision + WHEN data_type IN ('integer', 'bigint') THEN numeric_precision + ELSE NULL + END AS size + FROM + information_schema.columns + WHERE + table_schema = 'public' + AND Column_name = ? + AND table_name = ?",[$this->field, $this->table] + ); + + + $dataTypeDetails = reset($data); + + return [ + 'data_type' => $dataTypeDetails->data_type, + 'size' => $dataTypeDetails->size, + ]; + } } diff --git a/src/Queries/DatabaseTableFieldsClass.php b/src/Queries/DatabaseTableFieldsClass.php index afce63a..fded7bb 100644 --- a/src/Queries/DatabaseTableFieldsClass.php +++ b/src/Queries/DatabaseTableFieldsClass.php @@ -19,6 +19,7 @@ public function __invoke(): array { return match ($this->driver) { 'sqlite' => $this->sqlite(), + 'pgsql' => $this->pgsql(), default => $this->mysql(), }; } @@ -49,4 +50,18 @@ public function mysql(): array $fields = $this->select("Describe `$this->table`"); return array_column($fields, 'Field'); } + + public function pgsql(): array + { + $fields = DB::select( + "SELECT column_name,data_type, character_maximum_length, is_nullable,column_default + FROM + information_schema.columns + WHERE + table_schema = 'public' + AND table_name = ?",[$this->table] + ); + + return array_column($fields, 'column_name'); + } } diff --git a/src/Queries/DatabaseTableSizeClass.php b/src/Queries/DatabaseTableSizeClass.php index e78b88d..7df7484 100644 --- a/src/Queries/DatabaseTableSizeClass.php +++ b/src/Queries/DatabaseTableSizeClass.php @@ -19,6 +19,7 @@ public function __invoke(): string { return match ($this->driver) { 'sqlite' => $this->sqlite(), + 'pgsql' => $this->pgsql(), default => $this->mysql(), }; } @@ -58,5 +59,11 @@ public function mysql(): string } + public function pgsql(): string + { + $result = $this->select("SELECT pg_size_pretty(pg_table_size('".$this->table."')) AS size"); + return reset($result)?->size ?? Constant::DASH; + } + } diff --git a/src/Traits/DBFunctions.php b/src/Traits/DBFunctions.php index 0c8358e..43f31c2 100644 --- a/src/Traits/DBFunctions.php +++ b/src/Traits/DBFunctions.php @@ -52,7 +52,7 @@ public function checkTableExist(string $tableName): bool * Get Table List * @return array|string|int */ - public function getTableList(): array|string|int + public function getTableList(): array { $tableList = new DatabaseTableClass(); return $tableList(); diff --git a/src/Traits/Rules.php b/src/Traits/Rules.php index efb9f6d..5669247 100644 --- a/src/Traits/Rules.php +++ b/src/Traits/Rules.php @@ -27,6 +27,7 @@ public function allTablesRules(): array ->diff(config('db-auditor.skip_tables')) ->toArray(); + foreach ($tableList as $tableName) { $status = $this->checkStatus($tableName); $size = $this->getTableSize($tableName); @@ -113,18 +114,19 @@ public function fieldRules(string $tableName): array $checkFields = Constant::ARRAY_DECLARATION; try { $fields = $this->getFields($tableName); - + $fieldDT = []; foreach ($fields as $field) { $checkFields[$field] = $this->checkRules($field, Constant::FIELD_RULES); $dataTypeDetails = $this->getFieldDataType($tableName, $field); $checkFields[$field]['datatype'] = $dataTypeDetails; - if (connection_driver() === Constant::MYSQL_DB && $dataTypeDetails['data_type'] === Constant::DATATYPE_VARCHAR + if (connection_driver() === Constant::POSTGRESQL_DB && $dataTypeDetails['data_type'] === Constant::DATATYPE_VARCHAR && $dataTypeDetails['size'] <= Constant::DATATYPE_VARCHAR_SIZE ) { $checkFields[$field]['suggestion'] = __('Lang::messages.standard.error_message.datatype_change'); } } + } catch (Exception $exception) { Log::error($exception->getMessage()); } diff --git a/src/views/postgresql/constraint.blade.php b/src/views/pgsql/constraint.blade.php similarity index 100% rename from src/views/postgresql/constraint.blade.php rename to src/views/pgsql/constraint.blade.php diff --git a/src/views/postgresql/standard.blade.php b/src/views/pgsql/standard.blade.php similarity index 100% rename from src/views/postgresql/standard.blade.php rename to src/views/pgsql/standard.blade.php diff --git a/src/views/postgresql/table_standard.blade.php b/src/views/pgsql/table_standard.blade.php similarity index 100% rename from src/views/postgresql/table_standard.blade.php rename to src/views/pgsql/table_standard.blade.php From c3ddc61e371a8e62c002fc68d788e9dc06d2b28d Mon Sep 17 00:00:00 2001 From: Ruchit Patel Date: Thu, 1 Aug 2024 18:27:26 +0530 Subject: [PATCH 3/7] Refactor function. --- src/Commands/DBAuditCommand.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Commands/DBAuditCommand.php b/src/Commands/DBAuditCommand.php index 421aa04..6cd8d73 100644 --- a/src/Commands/DBAuditCommand.php +++ b/src/Commands/DBAuditCommand.php @@ -29,15 +29,13 @@ class DBAuditCommand extends Command */ public function handle(): void { - $commands = match (connection_driver()) { - Constant::SQLITE_DB => config('audit.sqlite_commands'), - Constant::MYSQL_DB => config('audit.mysql_commands'), - Constant::POSTGRESQL_DB => config('audit.pgsql_commands'), - }; - $commandSelect = select( label: 'Please Select feature which would you like to do', - options: $commands, + options: match (connection_driver()) { + Constant::SQLITE_DB => config('audit.sqlite_commands'), + Constant::MYSQL_DB => config('audit.mysql_commands'), + Constant::POSTGRESQL_DB => config('audit.pgsql_commands'), + }, default: Constant::SUMMARY_COMMAND ); From a94c53653217c252100f5526c5ef92b73b56255d Mon Sep 17 00:00:00 2001 From: Ruchit Patel Date: Fri, 2 Aug 2024 12:49:57 +0530 Subject: [PATCH 4/7] Update function return type. --- src/Traits/DBFunctions.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Traits/DBFunctions.php b/src/Traits/DBFunctions.php index f0f5ef1..22a6396 100644 --- a/src/Traits/DBFunctions.php +++ b/src/Traits/DBFunctions.php @@ -2,9 +2,7 @@ namespace Vcian\LaravelDBAuditor\Traits; -use Exception; -use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Log; + use Vcian\LaravelDBAuditor\Constants\Constant; use Vcian\LaravelDBAuditor\Queries\DatabaseCharacterSetClass; use Vcian\LaravelDBAuditor\Queries\DatabaseEngineClass; @@ -67,7 +65,7 @@ public function getTableList(): array public function getFieldsDetails(string $tableName): array { $fieldDetails = new DatabaseFieldDetailsClass($tableName); - return $fieldDetails() ?? Constant::ARRAY_DECLARATION; + return $fieldDetails(); } /** From 04e04ab725ae57f391ae9437a7e19e03768c9c19 Mon Sep 17 00:00:00 2001 From: Ruchit Patel Date: Fri, 2 Aug 2024 14:19:27 +0530 Subject: [PATCH 5/7] Update message. --- src/Commands/DBSummaryCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/DBSummaryCommand.php b/src/Commands/DBSummaryCommand.php index 1b1139a..56b1dd7 100644 --- a/src/Commands/DBSummaryCommand.php +++ b/src/Commands/DBSummaryCommand.php @@ -73,7 +73,7 @@ public function sqlite(): int public function mysql(): int { $this->table( - ['Database Name', 'Size', 'Table Count', 'DB Version', 'Character Set'], + ['Database Name', 'Size (MB)', 'Table Count', 'DB Version', 'Character Set'], [[ database_name(), $this->getDatabaseSize(), From ca7a0249f5b0c07c8f777a9e2955e546f553ac7a Mon Sep 17 00:00:00 2001 From: Ruchit Patel Date: Fri, 2 Aug 2024 15:08:38 +0530 Subject: [PATCH 6/7] Add MB in database table size. --- src/Commands/DBSummaryCommand.php | 2 +- src/Queries/DatabaseSizeClass.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Commands/DBSummaryCommand.php b/src/Commands/DBSummaryCommand.php index 56b1dd7..ab039c6 100644 --- a/src/Commands/DBSummaryCommand.php +++ b/src/Commands/DBSummaryCommand.php @@ -89,7 +89,7 @@ public function mysql(): int public function pgsql(): int { $this->table( - ['Database Name', 'Size', 'Table Count', 'Character Set'], + ['Database Name', 'Size (MB)', 'Table Count', 'Character Set'], [[ database_name(), $this->getDatabaseSize(), diff --git a/src/Queries/DatabaseSizeClass.php b/src/Queries/DatabaseSizeClass.php index cb4e977..df92527 100644 --- a/src/Queries/DatabaseSizeClass.php +++ b/src/Queries/DatabaseSizeClass.php @@ -66,10 +66,10 @@ public function mysql(): string public function pgsql(): string { $result = collect( - $this->select("SELECT pg_size_pretty( pg_database_size('".$this->database."') );") + $this->select("SELECT (pg_database_size('".$this->database."') / 1024 / 1024) AS size;") )->toArray(); - return reset($result)->pg_size_pretty ?? Constant::DASH; + return reset($result)->size ?? Constant::DASH; } From 503e35f150808951aaab7ebacaf2bbe061c2e139 Mon Sep 17 00:00:00 2001 From: Ruchit Patel Date: Fri, 2 Aug 2024 16:04:29 +0530 Subject: [PATCH 7/7] Code formatting. --- src/Traits/DBFunctions.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Traits/DBFunctions.php b/src/Traits/DBFunctions.php index 22a6396..67d6b43 100644 --- a/src/Traits/DBFunctions.php +++ b/src/Traits/DBFunctions.php @@ -86,11 +86,7 @@ public function getTableSize(string $tableName): string */ public function getFieldDataType(string $tableName, string $fieldName): array|bool { - $fieldDataType = new DatabaseTableFieldTypeClass( - $tableName, - $fieldName - ); - + $fieldDataType = new DatabaseTableFieldTypeClass($tableName, $fieldName); return $fieldDataType(); }