Hi,
On commit: 8285f6da17ff702f15129f505631c06aac1dc798 from @robindrost
The change from:
if (! class_exists('CreateWebSocketsStatisticsEntriesTable')) {
to
if (!Schema::hasTable('websockets_statistics_entries'))
in the provider breaks composer install/update as the provider's boot method is called on the post-dump script: php artisan package:discover --ansi.
The issue being that no database may be up at that stage.
Log dump from composer:
> post-autoload-dump: Illuminate\Foundation\ComposerScripts::postAutoloadDump
> post-autoload-dump: @php artisan package:discover --ansi
Executing command (CWD): '/usr/local/bin/php' -d allow_url_fopen='1' -d disable_functions='' -d memory_limit='-1' artisan package:discover --ansi
[2020-08-13 15:57:40] dev.ERROR: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = db_ecommerce and table_name = websockets_statistics_entries and table_type = 'BASE TABLE') {"exception":"[object] (Illuminate\\Database\\QueryException(code: 2002): SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = db_ecommerce and table_name = websockets_statistics_entries and table_type = 'BASE TABLE') at /www/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php:671)
[stacktrace]
#0 /www/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(745): Illuminate\\Database\\Connection->runQueryCallback('select * from i...', Array, Object(Closure))
#1 /www/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(725): Illuminate\\Database\\Connection->tryAgainIfCausedByLostConnection(Object(Illuminate\\Database\\QueryException), 'select * from i...', Array, Object(Closure))
#2 /www/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(634): Illuminate\\Database\\Connection->handleQueryException(Object(Illuminate\\Database\\QueryException), 'select * from i...', Array, Object(Closure))
#3 /www/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connection.php(339): Illuminate\\Database\\Connection->run('select * from i...', Array, Object(Closure))
#4 /www/htdocs/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php(18): Illuminate\\Database\\Connection->select('select * from i...', Array)
#5 /www/htdocs/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\\Database\\Schema\\MySqlBuilder->hasTable('websockets_stat...')
#6 /www/htdocs/vendor/beyondcode/laravel-websockets/src/WebSocketsServiceProvider.php(29): Illuminate\\Support\\Facades\\Facade::__callStatic('hasTable', Array)
#7 [internal function]: BeyondCode\\LaravelWebSockets\\WebSocketsServiceProvider->boot()
#8 /www/htdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): call_user_func_array(Array, Array)
#9 /www/htdocs/vendor/laravel/framework/src/Illuminate/Container/Util.php(37): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#10 /www/htdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#11 /www/htdocs/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(39): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#12 /www/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(596): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#13 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(867): Illuminate\\Container\\Container->call(Array)
#14 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(850): Illuminate\\Foundation\\Application->bootProvider(Object(BeyondCode\\LaravelWebSockets\\WebSocketsServiceProvider))
#15 [internal function]: Illuminate\\Foundation\\Application->Illuminate\\Foundation\\{closure}(Object(BeyondCode\\LaravelWebSockets\\WebSocketsServiceProvider), 15)
#16 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(851): array_walk(Array, Object(Closure))
#17 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\\Foundation\\Application->boot()
#18 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(230): Illuminate\\Foundation\\Bootstrap\\BootProviders->bootstrap(Object(Illuminate\\Foundation\\Application))
#19 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(310): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#20 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(127): Illuminate\\Foundation\\Console\\Kernel->bootstrap()
#21 /www/htdocs/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 {main}
[previous exception] [object] (PDOException(code: 2002): SQLSTATE[HY000] [2002] Connection refused at /www/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70)
[stacktrace]
#0 /www/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(70): PDO->__construct('mysql:host=127....', 'admin', 'admin', Array)
#1 /www/htdocs/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php(100): Illuminate\\Database\\Connectors\\Connector->createPdoConnection('mysql:host=127....', 'admin', 'admin', Array)
...
#25 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(850): Illuminate\\Foundation\\Application->bootProvider(Object(BeyondCode\\LaravelWebSockets\\WebSocketsServiceProvider))
#26 [internal function]: Illuminate\\Foundation\\Application->Illuminate\\Foundation\\{closure}(Object(BeyondCode\\LaravelWebSockets\\WebSocketsServiceProvider), 15)
#27 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(851): array_walk(Array, Object(Closure))
#28 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\\Foundation\\Application->boot()
#29 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(230): Illuminate\\Foundation\\Bootstrap\\BootProviders->bootstrap(Object(Illuminate\\Foundation\\Application))
#30 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(310): Illuminate\\Foundation\\Application->bootstrapWith(Array)
#31 /www/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(127): Illuminate\\Foundation\\Console\\Kernel->bootstrap()
#32 /www/htdocs/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#33 {main}
"}
In Connection.php line 671:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_s
chema.tables where table_schema = db_ecommerce and table_name = websockets_
statistics_entries and table_type = 'BASE TABLE')
In Connector.php line 70:
SQLSTATE[HY000] [2002] Connection refused
Note: Using the hardcoded table name websockets_statistics_entries might be wrong as the Model can be linked to an another table as:
class MyCustomModel extends WebSocketsStatisticsEntry
{
protected $table = 'my_custom_table_name';
}
@VictorDauchy good one!
In the initial fix i only changed the class name check to the correct name but changed it later to the schema check. Thought this would be better.
Would checking if the migration class exists be a better solution / be enough?
if (! class_exists('CreateWebSocketsStatisticsEntriesTable')) {
Well not even sure you really need to do any check as it will be run on every request (ie your current code may do 1 db call for every http request executed).
If you feel this is needed I would just keep a if (! class_exists(CreateWebSocketsStatisticsEntriesTable::class)) as it is a smaller overhead.
@VictorDauchy Seems to be fixed already :) https://github.com/beyondcode/laravel-websockets/pull/454/files
I'm closing the issue for now, check on the next release. 馃憖
@VictorDauchy @robindrost Tagged 1.6.0 with the fixes.
Most helpful comment
I'm closing the issue for now, check on the next release. 馃憖