Skip to content

[9.x] db:table command properly handle table who doesn't exist - #43669

Merged
taylorotwell merged 6 commits into
laravel:9.xfrom
kichetof:9.x
Aug 15, 2022
Merged

[9.x] db:table command properly handle table who doesn't exist#43669
taylorotwell merged 6 commits into
laravel:9.xfrom
kichetof:9.x

Conversation

@kichetof

Copy link
Copy Markdown
Contributor

New db:table doesn't proper handle table who doesn't exist.

When I first tried it, I run artisan db:table user (forgot the s) and instead of getting an error message I got an error:

   ErrorException 

  Attempt to read property "size" on null

  at vendor/laravel/framework/src/Illuminate/Database/Console/DatabaseInspectionCommand.php:89
     85▕     {
     86▕         return $connection->selectOne('SELECT (data_length + index_length) AS size FROM information_schema.TABLES WHERE table_schema = ? AND table_name = ?', [
     87▕             $connection->getDatabaseName(),
     88▕             $table,
  ➜  89▕         ])->size;
     90▕     }
     91▕ 
     92▕     /**
     93▕      * Get the size of a Postgres table in bytes.

      +16 vendor frames 
  17  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

This PR fix it by checking if table exists before accessing any properties.

@kichetof kichetof changed the title db:table command properly handle table who doesn't exist. [9.x] db:table command properly handle table who doesn't exist. Aug 11, 2022
Comment thread src/Illuminate/Database/Console/TableCommand.php Outdated
@driesvints driesvints changed the title [9.x] db:table command properly handle table who doesn't exist. [9.x] db:table command properly handle table who doesn't exist Aug 15, 2022
@taylorotwell
taylorotwell merged commit bbb9493 into laravel:9.x Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants